Contents
Note: "C-" means "Control-", and "M-" means "meta-" or "Esc-".
Starting emacs
To enter emacs, just type its name: emacs or emacs filename.
Leaving Emacs
| end emacs session | C-x C-c | |
| suspend emacs | C-z | |
Files
| read a file into emacs | C-x C-f | |
| save a file back to disk | C-x C-s | |
| insert contents of another file into this buffer | C-x i | |
| replace this file with the file you really want | C-x C-v | |
| write buffer to a specified file | C-x C-w | |
| run Dired, the directory editor | C-x d | |
Getting Help
The Help system is simple. Type C-h and follow the directions. If you are a first-time user, type C-h t for a tutorial.
| get rid of the Help window | C-x 1 |
| scroll Help window | ESC C-v |
| apropos: show commands matching a string | C-h a |
| show the function key runs | C-h c |
| describe a function | C-h f |
| get mode-specific information | C-h m |
Error Recovery
| abort partially typed or executing command | C-g |
| recover a file lost by a system crash | M-x recover-file |
| undo an unwanted change | C-x u or C-_ |
| restore a buffer to its original contents | M-x revert-buffer |
| redraw garbaged screen | C-l |
Incremental Search
| search forward | C-s |
| search backward | C-r |
| regular expression search | C-M-s |
If emacs is still searching, C-g will cancel the part of the search not done, otherwise it aborts the entire search.
Motion
| Cursor motion: | ||
|---|---|---|
| entity to move over | backward | forward |
| character | C-b | C-f |
| word | M-b | M-f |
| line | C-p | C-n |
| beginning or end of line | C-a | C-e |
| beginning or end of sentence | M-a | M-e |
| beginning or end of page | C-x [ | C-x ] |
| beginning or end of sexp | C-M-b | C-M-f |
| beginning or end of function | C-M-a | C-M-e |
| beginning or end of buffer | M-< | M-> |
| Scroll motion: | ||
| scroll to next screen | C-v | |
| scroll to previous screen | M-v | |
| scroll left | C-x < | |
| scroll right | C-x > |
Killing and Deleting
| Entity to kill | backward | forward |
| character (delete, not kill) | DEL | C-d |
| word | M-DEL | M-d |
| line (to end of) | M-0 C-k | C-k |
| sentence | C-x DEL | M-k |
| sexp | M-- C-M-k | C-M-k |
| kill region | C-w | |
| kill to next occurrence of char | M-z char | |
| yank back last thing killed | C-y | |
| replace last yank with previous kill | M-y |
Marking
| set mark here | C-@ or C-SPC |
| exchange point and mark | C-x C-x |
| set mark arg words away | M-@ |
| mark paragraph | M-h |
| mark page | C-x C-p |
| mark sexp | C-M-@ |
| mark function | C-M-h |
| mark entire buffer | C-x h |
| interactively replace a text string | M-% |
| using regular expressions | M-x query-replace-regexp |
| Valid responses in query-replace mode are: | |
| replace this time, go on to next | SPC |
| replace this one, don't move | . |
| skip to the next without replacing | DEL |
| replace all remaining matches | ! |
| back up to the previous match | ^ |
| exit query-replace | ESC |
| enter recursive edit (C-M-c to exit) | C-r |
Multiple Windows
| delete all other windows | C-x 1 |
| delete this window | C-x 0 |
| split window in 2 vertically | C-x 2 |
| split window in 2 horizontally | C-x 5 |
| scroll other window | C-M-v |
| switch cursor to other window | C-x o |
| shrink window shorter | M-x shrink-window |
| grow window taller | C-x ^ |
| select a buffer in other window | C-x 4 b |
| find file in other window | C-x 4 f |
| compose mail in other window | C-x 4 m |
| run Dired in other window | C-x 4 d |
| find tag in other window | C-x 4 . |
Formatting
| indent current line (mode-dependent) | TAB |
| indent region (mode-dependent) | C-M-\ |
| indent sexp (mode-dependent) | C-M-q |
| indent region rigidly arg columns | C-x TAB |
| insert newline after point | C-o |
| move rest of line vertically down | C-M-o |
| delete blank lines around point | C-x C-o |
| delete all white space around point | M-\ |
| put exactly one space at point | M-SPC |
| fill paragraph | M-q |
| fill region | M-g |
| set fill column | C-x f |
| set prefix each line starts with | C-x . |
Change Case
| uppercase word | M-u |
| lowercase word | M-l |
| capitalize word | M-c |
| uppercase region | C-x C-u |
| lowercase region | C-x C-l |
| capitalize region | M-x capitalize region |
The Minibuffer
| The following keys are defined in the minibuffer: | |
| complete as much as possible | TAB |
| complete up to one word | SPC |
| complete and execute | RET |
| show possible completions | ? |
| abort command | C-g |
| Type C-x ESC to edit and repeat the last command that used the minibuffer. The following keys are then defined: | |
| previous minibuffer command | M-p |
| next minibuffer command | M-n |