Cheat Sheet
Emacs comes with a lot of key combinations preconfigured. Some are so frequently used that they become second nature, some are so infrequently used that you are better off finding the name of the command when you need it. This list contains the ones that are in my grey zone - useful key combinations that aren't second nature yet.
Buffers
Key combination | Function | Description |
---|---|---|
C-xb | switch-to-buffer | Type the name of a buffer to display in the current window. If no buffer with the typed name exists, one will be created, which is not linked to a file. |
C-xC-b | list-buffers | Display a list of existing buffers in a new window, leaving the focus in the current window. |
C-xk | kill-buffer | Kill the current buffer, but do not harm the window itself. If the buffer is modified, and linked to a file, prompt for saving. |
C-xC-right | next-buffer | Display the next buffer in the current window, in the order they appear in the buffer-list (use C-xC-b to display the buffer-list). |
C-xC-left | previous-buffer | Display the previous buffer in the current window, in the order they appear in the buffer-list (use C-xC-b to display the buffer-list). |
Region: Select, Cut / Copy, and Paste
Key combination | Function | Description |
---|---|---|
C-space | set-mark-command | Selecting text in Emacs works by first setting the mark at one end of the desired selection, and then moving point to the other end. |
C-xh | mark-whole-buffer | Set the mark at the end of the buffer and move point to the beginning of the buffer, making the current region the whole buffer ("Select All" in other applications). |
C-xC-x | exchange-point-and-mark-nomark | Swap point and mark, without making the mark active (Use exchange-point-and-mark to also activate the mark). |
C-M-\ | indent-region | Indent the current region - this does something intelligent depending on the current major-mode. |
C-w | kill-region | Delete the current region and put it in the kill ring ("Cut" in other applications). |
C-y | yank | Insert the most recently killed text from the kill ring at point ("Paste" in other applications). Use yank-pop to cycle through the kill ring (no equivalent in most other applications). |
M-y | yank-pop | Only allowed immediately following a yank or yank-pop- cycles through the kill ring, inserting each entry in the kill ring at point. Only one entry from the kill ring will be inserted at point. |
Text editing
Key combination | Function | Description |
---|---|---|
M-% | query-replace | Replace one string by another, prompting the user for every match. Tries to preserve case for each match. |
M-q | fill-paragraph | Format point paragraph nicely - does a good job of detecting paragraph boundaries, very useful for breaking up long lines. |
M-space | just-one-space | Delete all whitespace around point, replacing it by ARG spaces (default is 1). |
M-d | kill-word | Delete the ARG words following the point (default is 1). |
C-backspace | backward-kill-word | Delete the ARG words preceding the point (default is 1). |
C-k | kill-line | Delete from point to the end of the line. |
Meta-commands
Key combination | Function | Description |
---|---|---|
C-g | keyboard-quit | Make Emacs stop doing whatever it is doing:
|
C-_
C-/ ( C-xu) |
undo | Undo the previous command. Pass a numeric argument (e.g. C-u4C-_) to undo the latest e.g. 4 changes. |
C-u <number> <command> | Invoke <command>, passing it <number> as an argument. | |
M-<number> <command> | Invoke <command> number times. | |
C-hl | view-lossage | Display the previous 100 typed characters - useful in combination with undo. |
C-x( | kmacro-start-macro | Begin defining a keyboard macro - subsequent keyboard input is executed and recorded, and can be executed again. Use C-g to abort the macro definition. |
C-x) | kmacro-end-macro | End defining a keyboard macro. |
C-xe | kmacro-end-and-call-macro | Invoke the most recently defined macro.
|
|
|
Pass a numeric argument to the next command (although a
preceding
C-u means something else to some commands,
see
C-hkC-u):
|
Windows
Key combination | Function | Description |
---|---|---|
C-x0 | delete-window | Close the current window (use C-x40 / kill-buffer-and-window to also kill the current buffer). |
C-x1
EscEscEsc |
delete-other-windows | Make the current window fill the entire current frame. |
C-x2 | split-window-vertically | Split the current window into two windows, one on top of the other, each occupying half the space. |
C-x3 | split-window-horizontally | Split the current window into two windows, one next to the other, each occupying half the space. |
C-x+ | balance-windows | Split the available space in the current frame evenly among the displayed windows. |
C-x^ | enlarge-window | Make the current window ARG lines higher (use shrink-window to make it ARG lines lower). |
C-x} | enlarge-window-horizontally | Make the current window ARG columns wider (use shrink-window-horizontally to make it ARG columns narrower). |
By default, only the functions which enlarge the active window have shortcuts. To shrink a window, either enlarge another window, or pass a negative ARG to an enlarging function. See Window Resize for more info.
Navigation
Key combination | Function | Description |
---|---|---|
M-<
C-home |
beginning-of-buffer | Move point to the top of the buffer. With argument, go to ARG*10 percent position in the file (from the top). |
M->
C-end |
end-of-buffer | Move point to the bottom of the buffer. With argument, go to 100-ARG*10 percent position in the file (from the top). |
C-a | move-beginning-of-line | Move point to the beginning of the line. |
C-e | move-end-of-line | Move point to the end of the line. |
M-gM-g | goto-line | Go to line number ARG. Prompt for a line number if no argument is given. If point is on a number, that number is the default for the prompt. |
C-l | recenter | Redraw the screen, and move the visible area of the current buffer so that point is in the middle of the current window. |
C-v / M-v | scroll-up | Display the next / previous screen of data from the buffer in the current window. |
C-left / M-left | backward-word | Move point to the first character of the word it is on. If point is already on the first character, move it to the first character of the preceding word. |
C-right / M-right | forward-word | Move point to the first character after the word it is on. If point is already on the first character after a word, move it to the first character after the next word. |
C-up | backward-paragraph | Move point to the first character of the paragraph it is on. If point is already on the first character, move it to the first character of the preceding paragraph. |
C-down | forward-paragraph | Move point to the first character after the paragraph it is on. If point is already on the first character after a paragraph, move it to the first character after the next paragraph. |
Bookmarks
For more details, see the GNU docs:
Key combination | Function | Description |
---|---|---|
C-x r l | list-bookmarks | List bookmarks. Also good for annotating and editing bookmarks - see C-x h m for more details. |
C-x r m
C-x r m name |
bookmark-set | Create a bookmark for the visible file at point. Optionally, the bookmark can be named (default is the file name). |
C-x r b name | bookmark-jump | Jump to the bookmark. |
M-x bookmark-delete | bookmark-delete | Delete a bookmark (prompts for the bookmark name). |
M-x bookmark-save | bookmark-save | Save the current bookmarks to a file. Bookmarks are saved in ~/.emacs.d/bookmarks or ~/.emacs.bmk as specified by bookmark-default-file. If bookmark-save-flag is set to 1, bookmarks will be saved every time they change. See also .emacs. |