Emacs is a fully-featured text editor that is both powerful and extensible out of the box, without needing to install any additional packages to make it work. With Emacs, you can easily manipulate text and files by executing Lisp commands. These commands, in turn, are then bound to a series of simple keybindings which allows you to focus on what you need to do.
Download this Cheatsheet
Enter your email below to receive this PDF cheatsheet in your Inbox.
Essential Emacs Keyboard Shortcuts
By default, Emacs already comes with a good number of shortcuts that you can use to do basic text editing, buffer manipulation and shell code execution. However, one issue with the default keyboard shortcuts for Emacs is that information about them are often either scant or obscure.
Knowing that, this cheatsheet aims to bridge that gap by highlighting some of Emacs’ most useful features. Further, this also includes how you can access them through simple keyboard shortcuts.
Shortcut | Function |
---|---|
General Emacs Controls | |
Ctrl + G | Cancel or suspend a command. |
Ctrl + G, then Ctrl + G, then Ctrl + G | Forcibly suspend a command. |
Ctrl + L | Refresh the current screen. |
Alt + X, then “recover session” | Restore any unsaved buffers. |
Ctrl + X, then Ctrl + C | Save all buffers and close Emacs. |
Alt + X, then “customize” | Open the built-in customization menu. |
File Manipulation | |
Ctrl + X, then Ctrl + F | Open a File Buffer. |
Ctrl + X, then Ctrl + S | Save the current file in the buffer. |
Ctrl + X, then S | Save all files in buffer. |
Ctrl + X, then Ctrl + D | Open a Dired Buffer. |
Ctrl + X, then Ctrl + W | Write the current file to a different buffer. |
Ctrl + X, then Ctrl + Q | Turn the current buffer to Read-Only. |
Text Selection | |
Alt + H | Select the paragraph before the cursor. |
Ctrl + Alt + H | Select the function before the cursor. |
Ctrl + X, then Ctrl + P | Select everything in the current screen. |
Ctrl + H | Select the entire buffer. |
Ctrl + Space | Activate the region select tool. |
Text Manipulation | |
Ctrl + W | Cut the text within the selected region. |
Ctrl + D | Cut the character after the |
Ctrl + K | Cut the entire line after the cursor. |
Alt + K | Cut the entire sentence after the cursor. |
Alt + U | Convert the word before the cursor to uppercase. |
Ctrl + X, then Ctrl + U | Convert the selected region to uppercase. |
Alt + L | Convert the word before the cursor to lowercase. |
Ctrl + X, then Ctrl + L | Convert the selected region to lowercase. |
Ctrl + T | Switch the two adjacent letters before the cursor. |
Alt + T | Switch the two adjacent words before the cursor. |
Text Formatting | |
Ctrl + O | Add a new line above the cursor. |
Ctrl + X, then Ctrl + O | Remove any empty lines around the cursor. |
Alt + \ | Remove all spaces around the cursor. |
Alt + Q | Truncate the paragraph to the current column length. |
Ctrl + X, F | Set the current column length. |
Searching and Replacing | |
Ctrl + S | Search for text after the cursor. |
Ctrl + R | Search for text before the cursor. |
Alt + P | Use the previously searched text for searching. |
Ctrl + Alt + S | Search for text after the cursor using regex. |
Ctrl + Alt + R | Search for text before the cursor using regex. |
M + % | Enter Emacs’ Interactive Replace menu. |
Buffer Movement | |
Ctrl + F | Move the cursor one character forward. |
Ctrl + B | Move the cursor one character backward. |
Alt + F | Move the cursor one word forward. |
Alt + B | Move the cursor one word backward. |
Ctrl + N | Move the cursor one line down. |
Ctrl + P | Move the cursor one line up. |
Ctrl + V | Scroll the entire buffer screen down. |
Alt + V | Scroll the entire buffer screen up. |
Ctrl + E | Move the cursor to the end of the current line. |
Ctrl + A | Move the cursor to the start of the current line. |
Alt + E | Move the cursor to the end of the current sentence. |
Alt + A | Move the cursor to the start of the current sentence. |
Buffer Manipulation | |
Ctrl + X, then 2 | Split the current buffer horizontally. |
Ctrl + X, then 3 | Split the current buffer vertically. |
Ctrl + X, then 4, then B | Open an existing buffer as a vertical split. |
Ctrl + X, then 4, then F | Open a file as a vertical split. |
Ctrl + X, then 4, then D | Open directory as a vertical split. |
Ctrl + X, then 1 | Delete all other splits aside from the currently selected one. |
Ctrl + X, then 0 | Delete the currently selected split. |
Ctrl + X, then B | Switch to a different buffer. |
Ctrl + X, then Ctrl + B | Print a list of all existing buffers. |
Command Buffer Controls | |
? | Suggest potential completion options. |
Alt + P | Rewrite the previous command in the buffer. |
Alt + R | Search backwards through the command buffer history. |
Alt + F | Search forwards through the command buffer history. |
Shell Support | |
Alt + X, then “term” | Open a VT100 Terminal Emulator. |
Alt + X, then “eshell” | Open an Emacs Lisp Terminal. |
Alt + ! | Run a shell command from the command buffer. |
Alt + & | Run a shell command and fork the process to the background. |
Keyboard Macros | |
Ctrl + X, then ( | Create an Emacs keyboard macro. |
Ctrl + X, then ) | Save an Emacs keyboard macro. |
Ctrl + X, then E | Run the last Emacs macro defined. |
Lisp-specific Functions | |
Ctrl + X, then Ctrl + E | Run the currently selected Lisp expression. |
Ctrl + Alt + X | Run the currently selected a Lisp function. |
Emacs Help System | |
Ctrl + H, then ? | Open a summary of all the options for the Help system. |
Ctrl + H, then A | Search for a specific Help topic. |
Ctrl + H, then F | Open a Help window about the highlighted Lisp function. |
Ctrl + H, then V | Open a Help window about the highlighted Lisp variable. |
Ctrl + H, then M | Open a Help window for the current Major Mode. |
Ctrl + H, then P | Search for an installed Emacs package. |
Ctrl + H, then Shift + P | Search for the documentation of an Emacs package. |
Ctrl + H, then I | Open the Emacs Info Screen. |
Ctrl + H, then Ctrl + F | Open the Emacs FAQ. |
Ctrl + H, then Ctrl + N | View the most recent news about Emacs. |
Emacs Info Screen | |
H | Open the Info Screen tutorial. |
Space | Scroll down the currently displayed text by half a screen. |
Backspace | Scroll up the currently displayed text by half a screen. |
N | Go to the next Info node for the document. |
P | Go to the previous Info node for the document. |
T | Go to the top Info node for the document. |
D | Go to the document’s Table of Contents. |
L | Go back to the last Info node that you read. |
Q | Exit Emacs’ Info Screen Mode. |
Image credit: Unsplash
Our latest tutorials delivered straight to your inbox