Emacs is a highly extensible and customizable text editor that offers a wide range of features along with comprehensive flexibility. It is a versatile text editor that can be used on various operating systems. Emacs is quite handy for beginners and experienced users because of its convenient functionalities. In this article, you will find a cheat sheet on Emacs where I have listed several shortcuts and keybindings which is a wonderful resource for anyone who wants to explore this text editor deeply.
Download Emacs Cheat Sheet
Keyboard Shortcuts of Emacs
There are key shortcuts for each and every task in the Emacs text editor. These shortcuts are truly helpful for increasing working capacity. The following section contains a comprehensive list of keyboard shortcuts of Emacs used frequently.
Getting Started
The following shortcuts will help you to know how to launch and exit the Emacs text editor.
Type emacs to enter Emacs text editor |
Shortcut Keys |
Description |
CTRL + Z |
Suspend Emacs |
CTRL + X + CTRL + C |
Exit Emacs permanently |
Navigation
Navigation shortcuts are used to move around a document & open files and tabs quickly. You can navigate quite easily using the shortcuts given below:
Shortcut Keys |
Description |
CTRL + F |
Move forward one character |
CTRL + B |
Move backward one character |
ALT + F |
Move forward one word |
ALT + B |
Move backward one word |
CTRL + N |
Move to the next line |
CTRL + P |
Move to the previous line |
CTRL + A |
Move to the beginning of the line |
CTRL + E |
Move to the end of the line |
ALT + A |
Move to the beginning of the current sentence |
ALT + E |
Move to the end of the current sentence |
ALT + { |
Move to the beginning of the paragraph |
ALT + } |
Move to the end of the paragraph |
ALT + < |
Move to the beginning of the buffer |
ALT + > |
Move to the end of the buffer |
ALT + N |
Move forward through the command history |
ALT + P |
Move backward through the command history |
CTRL + L |
Center the display on the current line |
Case Conversion
You can perform various case conversions on text using the shortcuts listed below:
Shortcut Keys |
Description |
ALT + L |
Convert a word to lowercase |
ALT + U |
Convert a word to uppercase |
ALT + C |
Capitalize a word |
CTRL + X + CTRL + L or ALT + X downcase-region |
Convert a selected region to lowercase |
CTRL + X + CTRL + U or ALT + X upcase-region |
Convert a selected region to uppercase |
ALT + X capitalize-region |
Capitalize the first character of each word in the selected region |
File Handling
Emacs provides a huge range of file-handling capabilities. Here are some common syntaxes to manipulate files in Emacs.
Shortcut Keys |
Description |
CTRL + X + CTRL + F |
Open a file |
CTRL + X + CTRL + S |
Save the current buffer |
CTRL + X + S |
Save all buffers |
CTRL+X + I |
Insert a file into the current buffer |
CTRL + X + CTRL + W |
Write the current buffer to a different file (Save file as…) |
CTRL + X + CTRL + V |
Visit a different file in the current buffer |
CTRL + X + CTRL + Q |
Toggle read-only mode for current buffer |
CTRL + X + CTRL + R |
Rename file |
CTRL + X + CTRL + D |
Delete file |
CTRL + X + CTRL + A |
Edit file as root |
Formatting
Formatting means adjusting indentation, spacing, alignment etc. As Emacs offers extensive formatting options, you can define your own customized preferences using the syntax below:
Shortcut Keys |
Description |
TAB |
Indent the current line |
CTRL + ALT + \ |
Indent the region by aligning it properly |
CTRL + ALT + Q |
Reformat the current paragraph |
CTRL + X + TAB |
Indent region by specific number of spaces |
ALT + ; |
Comment or uncomment the current line or selected region |
CTRL + O |
Insert a new line after the current line |
CTRL + ALT + O |
Split current line at cursor point and move the rest text to the new line |
CTRL + X + CTRL + O |
Delete blank lines around cursor point, leaving one blank line |
ALT + ^ |
Join current line with previous line by removing the whitespace of current line |
ALT + \ |
Delete all whitespace around cursor point |
ALT + SPACE |
Force putting one space at cursor point |
ALT + Q |
Fill paragraph at cursor point |
CTRL + X + F |
Set the fill column to a special value |
CTRL + X + . |
Set prefix each line starts with at cursor point |
ALT + O |
Open a new line below current line & move cursor to new line, preserving indentation |
Getting Help
In Emacs, you can easily get help and access documentation. Explore the syntax below and enhance your Emacs experience:
Shortcut Keys |
Description |
CTRL + H + T |
Open the Emacs tutorial |
CTRL + H + K |
Describe the function bound to a key sequence |
CTRL + H + F |
Describe a specific function by name |
CTRL + H + V |
Describe a specific variable by name |
CTRL + H + W |
Display the key bindings for a given command |
CTRL + H + B |
Show all key bindings currently in effect |
CTRL + H + A |
Show commands matching a string |
CTRL + H + M |
Get mode-specific information |
CTRL + H + CTRL + F |
Open a file using the built-in Emacs file browser |
CTRL + H + CTRL + A |
Show the Emacs command-line arguments |
CTRL + H + CTRL + C |
Describe the Emacs copying conditions |
CTRL + H + CTRL + D |
Display the GNU Emacs distribution details |
CTRL + H + CTRL + M |
Display the GNU Emacs manual in Info format |
CTRL + H + CTRL + P |
Describe the Emacs package system |
n |
Move to the next page or section in the help buffer |
p |
Move to the previous page or section in the help buffer |
SPACE |
Scroll down by one windowful in the help buffer |
DEL |
Scroll up by one windowful in the help buffer |
b |
Scroll up by one page in the help buffer |
f |
Scroll down by one page in the help buffer |
u |
Scroll up by half a page in the help buffer |
m |
Return to the top-level menu in the help buffer |
g |
Revert the help buffer to its original state |
q |
Quit the help buffer |
Frames
Frame refers to a graphical window that includes multiple windows. This allows you to work with multiple views of Emacs at one time. Here are some common syntax related to frames:
Shortcut Keys |
Description |
CTRL + X + 5 + 2 |
Split the current frame horizontally by creating a new frame |
CTRL + X + 5 + 3 |
Split the current frame vertically by creating a new frame |
CTRL + X + 5 + 0 |
Close the current frame |
CTRL + X + 5 + O |
Cycle through the available frames |
CTRL + X + 5 + B |
Switch to a different buffer in another frame |
CTRL + X + 5 + + |
Increase the size of the current frame horizontally |
CTRL + X + 5 + – |
Decrease the size of the current frame horizontally |
CTRL + TAB |
Switch to the next frame |
ALT + S + ARROWS |
Resize frame |
CTRL + X + 5 + R |
Rename the current frame |
CTRL + X + 5 + F |
Open a file in a new frame |
CTRL + C + S + A |
Scroll all frames simultaneously |
Multiple Windows
The multiple Windows shortcuts are a convenient way to view and edit different buffers simultaneously. One can easily manipulate and edit text in Emacs using the shortcuts below:
Shortcut Keys |
Description |
CTRL + X + 0 |
Close the current window |
CTRL + X + 1 |
Close all other windows, keeping only the current window |
CTRL + X + 2 |
Split the current window vertically into two windows |
CTRL + X + 3 |
Split the current window horizontally into two windows |
CTRL + X + O |
Switch to the next window |
CTRL + X + ^ |
Enlarge the current window vertically |
CTRL + X + { |
Shrink the current window horizontally |
CTRL + X + } |
Enlarge the current window horizontally |
CTRL + ALT + V |
Scroll other windows |
CTRL + X + R + W |
Save the current window configuration to a register |
CTRL + X + R + J |
Jump to a previously saved window configuration |
CTRL + X + 4 + B |
Open a buffer in a new window |
CTRL + X + 4 + F |
Open a file in a new window |
CTRL + X + 4 + R |
Open a read-only file in a new window |
CTRL + X + 4 + D |
Open and access contents of a directory in a separate window using Dired mode |
CTRL + X + 4 + . |
Find tag in other windows |
Dired (Open With CTRL+X+D)
In Emacs, Dired is a built-in file management mode. It allows you to perform various operations on files such as opening, copying, moving, deleting, navigating, etc. Use the following syntax to work easily with files in this text-based interface:
Shortcut Keys |
Description |
C/R/D |
Copy/rename/delete |
!/& |
Shell command/asynchronous |
Z |
Compress/uncompress |
M/G/O |
Change mode/group/owner |
A/Q |
Search/replace |
m/u/U |
Mark/unmark/unmark all |
+ |
New directory |
g |
Refresh |
Marking
Marking indicates the process of highlighting or selecting a region of text to perform operations on them. Here are some popular techniques for marking:
Shortcut Keys |
Description |
CTRL + @ or CTRL + SPACE |
Set the mark at the current cursor position |
CTRL + X + CTRL + X |
Exchange the cursor position with the mark position |
ALT + @ |
Mark the next word as the region |
ALT + H |
Mark the current paragraph |
CTRL + X + CTRL + P |
Mark page |
CTRL + ALT + @ or CTRL + ALT + SPACE |
Mark the current function |
CTRL + ALT + H |
Mark the entire current buffer |
CTRL + X + H |
Mark the entire buffer |
CTRL + ALT + <SPACE> |
Mark the next expression or block of text |
CTRL + ←, CTRL + →, CTRL + ↑, CTRL + ↓ |
Mark by word or line in the respective direction |
Screens
Screen is the visual display where buffers, frames and windows are presented. Following are some fundamental shortcuts regarding Emacs screen:
Shortcut Keys |
Description |
F9 |
Create new screen |
S + F9 |
Kill current screen |
ALT + 1…ALT + 0 |
Go to screen number 1 … 10 |
CTRL + Z + L |
List active screens |
CTRL + Z + CTRL + B |
Escreen manu |
Desktop
Desktop in Emacs is a feature that helps you to save and restore your entire editing session. It is helpful when you have a complex window setting. Some key shortcuts related to Emacs desktop are given below:
Shortcut Keys |
Description |
CTRL + X + X + R |
Load session |
CTRL + X + X + S |
Save current session |
CTRL + X + X + D |
Save current session & clear |
CTRL + X + X + C |
Change session (save & load) |
CTRL + X + X + N |
Show current session name |
Google
Using the handy shortcuts given below, you can easily perform Google searches in Emacs:
Shortcut Keys |
Description |
CTRL + C + G + RET |
Google search |
CTRL + C + G + G |
Google search on cursor |
CTRL + C + G + R |
Google C++ reference |
CTRL + C + G + M |
Google maps search |
CTRL + C + t |
Google translate at point |
CTRL + C + T |
Google translate |
Transposing
Transposing means swapping characters, words and lines. Here are several syntaxes for transposing text elements in Emacs:
Shortcut Keys |
Description |
CTRL + T |
Transpose characters |
ALT + T |
Transpose words |
CTRL + X + CTRL + T |
Transpose lines |
CTRL + ALT + T |
Transpose sexps (balanced expression) |
CTRL + V |
Scroll forward |
ALT + V |
Scroll backward |
CTRL + X + < |
Scroll left |
CTRL + X + > |
Scroll right |
ALT + G + G |
Go to line |
ALT + G + C |
Go to character |
ALT + M |
Move to first non-whitespace character on the line |
Killing and Deleting
Killing and deleting shortcuts allow you to remove text in different ways. Using the killing syntax you can remove text and place it into the kill ring for later use. On the contrary, using the deleting syntax you can remove text without storing it. Some basic shortcuts for killing and deleting text in Emacs are given below:
Shortcut Keys |
Description |
CTRL + K |
Kill (cut) text from the cursor position to the end of the line |
ALT + K |
Kill text from the cursor position to the end of the current sentence |
CTRL + W |
Kill text from the cursor position to the end of the current sentence |
ALT + D |
Kill the word following the cursor |
DEL |
Delete the character before the cursor |
ALT + DEL |
Delete the word before the cursor |
CTRL + X + DEL |
Kill backward from the cursor to the previous whitespace |
CTRL + D |
Delete the character at the cursor |
ALT + <DEL>. |
Delete the line before the cursor |
CTRL + Y |
Yank (paste) the last killed text at the cursor position |
ALT + Y |
Replace last yank with previous kill |
ALT + W |
Copy region to kill ring |
Info
Info is the built-in documentation that provides compact information about any topic regarding Emacs. To access info follow the keybindings below:
Shortcut Keys |
Description |
CTRL + H + I |
Open info system and display info menu |
CTRL + H + S |
Open emacs FAQ |
SPACE |
Scroll forward in info buffer |
DEL |
Scroll backward in info buffer |
b |
Beginning of an info node |
n |
Move to the next info node |
p |
Move to the previous Info node |
u |
Go up one level in the Info hierarchy |
m |
Go to the Info menu |
n |
Move to the next Info node |
f |
Follow a cross-reference to another Info node |
l |
Follow a link to an external file or URL |
d |
Follow a directory reference to browse a directory |
t |
Toggle between the table of contents and the current node |
g |
Go to a specific Info node by name |
h |
Display the Info help message |
i |
Display information about the current node |
s |
Search for a specific text or pattern in the current node |
q |
Quit the Info system and return to the previous buffer |
Tags
Tag is the mechanism for indexing and navigating the source code of any language. Using tags you can easily jump to your desired locations. Some key bindings related to tags in Emacs:
Shortcut Keys |
Description |
ALT + . |
Find a tag (a definition) |
ALT + * |
Return to the previous location before the last jump |
CTRL + U + ALT + . |
Find next occurrence of tag |
ALT + X visit-tags-table |
Visit an existing tags file or create a new one |
ALT + X compile-tags |
Generate a new tags file using specific command |
ALT + X build-tags |
Build a tags file recursively for all files in a directory |
ALT + X tags-apropos |
Search for symbols matching a particular pattern |
ALT + X tags-loop-continue |
Continue a tag search |
ALT + X tags-revert-buffer |
Update current buffer with changes made to tags file |
ALT + X tags-reset-tags-table |
Clear list of visited tags table |
ALT + X tags-search |
Regex search on all files in tag table |
ALT + X tags-query-replace |
Run query and replace on all files |
ALT + , |
Continue last tags search or query-replace |
Buffers
A buffer is a temporary workspace that holds text. These are used to display help info, edit files, run shell commands, etc. A list of shortcuts related to the Emacs buffer is given below:
Shortcut Keys |
Description |
CTRL + X + B |
Select another buffer |
CTRL + X + CTRL + B |
List all buffers |
CTRL + X + K |
Kill a buffer |
ALT + X rename-buffer |
Rename the current buffer |
CTRL + G |
Abort the current operation of a keyboard macro |
TAB |
Complete as much as possible |
SPACE |
Complete up to one word |
RET |
Complete and execute |
Regex
Emacs extends powerful Regex (Regular Expression) accommodation. Knowing about the regex in Emacs you can search, match, and manipulate text in a convenient way. The regex in Emacs is given below:
Shortcut Keys |
Description |
^ |
Start of a line anchor |
$ |
End of a line anchor |
\< |
Start of a word anchor |
\> |
End of a word anchor |
\_< |
Start of a word or buffer anchor |
\_> |
End of a word or buffer anchor |
\‘ |
Start of a sentence anchor |
\’ |
End of a sentence anchor |
. |
Match any single character except a newline |
* |
Match zero or more repeats of the preceding element |
+ |
Match one or more repeats of the preceding element |
? |
Match zero or one repeat of the preceding element |
\ |
Quote special characters |
\| |
Match either the expression before or after the vertical bar |
\(…\) |
Group the enclosed regular expression as subexpression |
\(:?…\) |
Match the enclosed regular expression but doesn’t store it |
\(:NUM…\) |
Match the same text that was matched by the ‘NUM’th sub-expression before |
\n |
Match the same text that was matched by the ‘n’th sub-expression before |
\b |
Match a word break |
\B |
Match a position that is not a word break |
[…] |
Match character present within the brackets |
[^…] |
Match character that is not present within the brackets |
\w |
Match any word character |
\W |
Match non word character |
\sc |
Match character with the specified syntax class |
\Sc |
Match character that doesn’t belong to the specified syntax class |
\cc |
Match character with the specified character category |
\Cc |
Match character that doesn’t belong to the specified character category |
Search
To find a specific text within a buffer you can perform search operations in Emacs using the keybindings below:
Shortcut Keys |
Description |
CTRL + S |
Search forward |
CTRL + R |
Search backward |
ALT + X regexp |
Search using a regular expression |
CTRL + ALT + S |
Search forward using a regular expression |
CTRL + ALT + R |
Search backward using a regular expression |
ALT + S |
Forward search Regex through history |
ALT + R |
Backward search Regex through history |
Query Replace
Query replace allows you to search for a pattern and replace it with another string. Here is how to perform query replace operation in Emacs:
Shortcut Keys |
Description |
ALT + % |
Replace a text string |
CTRL + ALT + % |
Replace all occurrences |
SPACE / y |
Replace and move to the next occurrence |
DEL / n |
Skip to the next occurrence without replacing |
! |
Replace all remaining occurrences without further prompting |
RET |
Exit query replace |
Error Recovery
One can easily recover from an unexpected error in Emacs using the following shortcuts:
Shortcut Keys |
Description |
ALT + X recover-session |
Recover a previous Emacs session |
CTRL + _ or CTRL + / |
Undo the last change made in Emacs |
ALT + X revert-buffer |
Recover files lost by a system crash |
CTRL + L |
Clear the current screen & redraw the contents of the buffer |
CTRL + G |
Cancel a running Emacs command or quit a partially entered command |
Miscellaneous
Some keystrokes for miscellaneous Emacs are below:
Shortcut Keys |
Description |
ALT + ! |
Execute a shell command |
ALT + & |
Execute a shell command asynchronously |
ALT + | |
Run a shell command on the region |
CTRL + U + ALT + | |
Filter region through a shell command |
ALT + X shell |
Start a shell in window shell |
CTRL + X + R + I |
Insert register contents into buffer |
CTRL + X + R + J |
Jump to point saved in register |
CTRL + X + R + S |
Save region in register |
CTRL + X + R + SPACE |
Save value of point in register |
CTRL + X + RET + L |
Specify principal language |
CTRL + U num |
Numeric argument |
ALT + – |
Negative argument |
CTRL + X + A + G |
Add global abbrev |
ALT + $ |
Check spelling of current word |
ALT + X ispell-region |
Check spelling of all words in region |
ALT + X ispell-buffer |
Check spelling of entire buffer |
ALT + X flyspell-mode |
Toggle on-the-fly spell checking |
Conclusion
The whole article is a handy reference guide that explains the essential keybindings of Emacs. By utilizing the whole guide of the Emacs cheat sheet, you can optimize your workflow and leverage the experience of using this text editor.