Emacs Cheat Sheet


Notation
C-x Hold down CONTROL and press x
M-x Press and release ESC, then press x
(On some machines, you can hold down ALT and press x)

Starting, Quitting, and Help
emacs file --> From the UNIX command line, open file in emacs.
C-x C-c  --> Quit emacs
C-g  --> Abort current command
C-x u  --> Undo last command
C-h t  --> Run tutorial

Moving Around
C-a  --> Beginning of line
C-e  --> End of line
M-v  --> Page up
C-v  --> Page down
M-<  --> Beginning of file
M->  --> End of file
C-l  --> Center window on cursor

Files, Buffers, and Windows
C-x C-f  --> Open (or create a new file)
C-x C-s  --> Save
C-x C-w  --> Save as (write)
C-x b  --> Switch to another buffer
C-x 2  --> Split window in two
C-x 1  --> Return to a single window
C-x o  --> Move to other window

Editing
C-s  --> Search
M-%  --> Find and replace, with verification of each instance
M-x  --> replace-string Find and replace
C-SPACE  --> Set mark
C-w  --> Cut
M-w  --> Copy
C-y  --> Paste (“yank” something into existence)
C-k  --> Cut rest of current line (use again to cut end-of-line too)

Intermediate Tricks
M-;  --> Insert comment in code
M-x  --> comment-region Comment selected region
M-x  --> uncomment-region Uncomment selected region
C-u 5  --> command Perform command 5 times
(Any other number works, too)
C-x  --> ( Begin recording keyboard macro
C-x )  --> End recording keyboard macro
C-x e  --> Run last keyboard macro
M-/  --> Complete the current word
(If emacs guesses wrong, try again)
M-x  --> dunnet Play dungeon adventure game

other
M-x lusty-file-explorer --> call file explorer (when lusty file explorer is installed)
M-x lusty-buffer-explorer --> call buffer explorer (when lusty file explorer is installed)
C-x f --> close file
M-x revert-buffer RET --> refresh buffer list
C-u C-x TAB --> indent block to four spaces right
C-u -4 C-x TAB --> indent block to four spaces left
M-x goto-line --> Read a number and go to that line (first line = 1).
C-M-f --> find matching brace forward
C-M-b --> find matching brace backward