Emacs cheat sheet

Last updated 2/6/2008 by Darryl Yong

This file contains useful keyboard shortcuts for emacs. Please send corrections or suggestions to dyong@hmc.edu.

C-{key} means hold down [CONTROL] with the specified key.
M-{key} means press META (usually the [ESCAPE] key) first then the specified key.

Essential keys:

C-h iGet Help using Info
C-h aGet Help using apropos (useful when you know what you want to do but don't know the command name)
C-gQuit out of any command and puts the cursor back in the editing window
C-x C-cQuit emacs
C-x C-sSave the file you're working on
C-x C-wSave the file you're working on under new name
C-_Undo
C-x C-fOpen a new file (opens a new buffer if needed)
C-x C-kKill the current buffer
C-x C-bSwitch to another buffer
M-xPress this to issue a command to emacs (tab completion works)

Moving:

C-vMove one screenful down (also [PageUp])
M-vMove one screenful up (also [PageDown])
C-aMove to the beginning of the line
C-eMove to the end of the line
M-<Move to the beginning of the buffer
M->Move to the end of the buffer
C-[space]Set the mark to the current location of the cursor (actually, this adds the location to the mark ring)
C-u C-[space]Put the cursor back to the mark (actually, cycles through the positions in the mark ring if used repeatedly)
C-lCenter window around the current line (and refresh window)
C-x 2Split window vertically
C-x oSwitch to other window
C-x 1Delete other windows (go back to a single window)

Editing:

C-dDelete one character (also [Del] key on the keyboard)
C-kKill a line (this is like "cut"--actually puts the line(s) onto the kill ring)
C-yYank back the lines on the kill buffer (this is like "paste"--actually uses the first block of text on the kill ring)
M-yCycle through the kill ring (only works after issuing a yank)
C-wKill region (everything between the mark and the current location of the cursor)
C-sSearch (forward)
C-rSearch (reverse)
M-%Search and replace (interactive, use ! to replace all)

LaTeX specific keys:

C-c C-cCompile LaTeX file (can view and issue other commands on the source file)
C-c C-;Comment region (everything between the mark and the current location of the cursor)
C-c `If an error occurs while compiling, this puts the cursor where the error occured
M-C-fMove cursor to matching parenthesis, bracket, or brace

Nifty things:

C-x r kKill a rectangle of text (using the mark and current location of cursor as the corners of the rectangle)
C-x r yYank rectangle
C-x (Begin recording a sequence of keystrokes as a macro
C-x )Stop recording a macro (any ringing of the bell will cause the recording to abort)
C-x eExecute the recorded macro
M-{number} C-x eExecute the macro {number} times
M-x query-replace-regexpSearch and replace using regular expressions
C-u 0 M-x byte-recompile-directoryRecompile a whole directory of Lisp files (useful when installing AUCTeX, for example)