Emacs Cheatsheet
#
Emacs is a highly customizable and extensible text editor. It is known for its powerful features and extensive keyboard shortcuts, making it suitable for a wide range of tasks.
Basic Navigation
#
Command/Option | Example | Description |
---|
C-f | C-f | Move cursor forward by one character |
C-b | C-b | Move cursor backward by one character |
C-n | C-n | Move cursor to the next line |
C-p | C-p | Move cursor to the previous line |
M-f | M-f | Move cursor forward by one word |
M-b | M-b | Move cursor backward by one word |
C-a | C-a | Move cursor to the beginning of the line |
C-e | C-e | Move cursor to the end of the line |
M-< | M-< | Move cursor to the beginning of the buffer |
M-> | M-> | Move cursor to the end of the buffer |
Editing Text
#
Command/Option | Example | Description |
---|
C-d | C-d | Delete the character under the cursor |
M-d | M-d | Delete the word forward |
C-k | C-k | Kill (cut) text from the cursor to the end of the line |
C-y | C-y | Yank (paste) the previously killed text |
M-y | M-y | Cycle through the killed texts |
C-x C-s | C-x C-s | Save the current buffer |
C-x C-c | C-x C-c | Exit Emacs |
C-/ or C-x u | C-/ or C-x u | Undo the last action |
C-space | C-space | Set the mark (start selection) |
Search and Replace
#
Command/Option | Example | Description |
---|
C-s | C-s search_term | Search forward for “search_term” |
C-r | C-r search_term | Search backward for “search_term” |
M-% | M-% old_text RET new_text RET | Replace “old_text” with “new_text” in the buffer |
File Operations
#
Command/Option | Example | Description |
---|
C-x C-f | C-x C-f filename | Open or create a file named “filename” |
C-x C-w | C-x C-w newfile | Save the current buffer as “newfile” |
C-x k | C-x k | Kill (close) the current buffer |
C-x b | C-x b buffer_name | Switch to the buffer named “buffer_name” |
Window Management
#
Command/Option | Example | Description |
---|
C-x 2 | C-x 2 | Split the window horizontally |
C-x 3 | C-x 3 | Split the window vertically |
C-x 1 | C-x 1 | Delete other windows, keeping only the current one |
C-x o | C-x o | Switch to the other window |
Buffer Management
#
Command/Option | Example | Description |
---|
C-x b | C-x b buffer_name | Switch to the buffer named “buffer_name” |
C-x C-b | C-x C-b | List all buffers |
C-x k | C-x k buffer_name | Kill (close) the buffer named “buffer_name” |
Customization and Help
#
Command/Option | Example | Description |
---|
M-x | M-x command | Execute a command by name |
C-h t | C-h t | Open the Emacs tutorial |
C-h f | C-h f function_name | Display documentation for “function_name” |
C-h v | C-h v variable_name | Display documentation for “variable_name” |
M-x customize | M-x customize | Open the customization interface |
Advanced Commands
#
Command/Option | Example | Description |
---|
M-x shell | M-x shell | Open a shell within Emacs |
M-x term | M-x term | Open a terminal emulator within Emacs |
M-x magit | M-x magit | Open the Magit interface for Git version control |
This cheatsheet covers the essential Emacs commands and options to help you navigate, edit, and manage text efficiently in Emacs.