GNU Emacs is the legendary extensible editor, and its entire interface is keyboard commands. The notation is simple once you know it: C-x means hold Ctrl and press x, and M-x means hold Alt (Meta) and press x. This complete list of Emacs keyboard shortcut keys explains files, movement, editing, search, macros and windows in plain words.
Files, Buffers and Help Shortcuts
| Shortcut Key | Function |
|---|---|
| Ctrl + x, then Ctrl + f (C-x C-f) | Find (open) a file |
| C-x C-s | Save the current buffer to its file |
| C-x s | Save some buffers (asks for each modified one) |
| C-x C-w | Write the buffer to a new file name (Save As) |
| C-x b | Switch to another buffer by name |
| C-x C-b | List all buffers |
| C-x Left / Right Arrow | Previous / next buffer |
| C-x k | Kill (close) a buffer |
| C-x C-c | Exit Emacs |
| C-g | Cancel the current command (the universal escape hatch) |
| C-/ or C-x u | Undo |
| M-x | Run any command by name (the Command Palette of Emacs) |
| C-h t | Open the built-in tutorial |
| C-h k | Describe what a key does |
| C-h f | Describe a function |
| C-h a | Apropos: search commands by keyword |
| C-h m | Describe the current major/minor modes and their keys |
Movement Shortcuts
| Shortcut Key | Function |
|---|---|
| C-f / C-b | Move forward / backward one character |
| C-n / C-p | Move to the next / previous line |
| M-f / M-b | Move forward / backward one word |
| C-a / C-e | Move to the start / end of the line |
| M-a / M-e | Move to the start / end of the sentence |
| M-{ / M-} | Move to the previous / next paragraph |
| C-v / M-v | Scroll down / up one screen |
| M-< / M-> | Go to the beginning / end of the buffer |
| M-g, then g (M-g g) | Go to a line number |
| C-l | Recenter the screen on the cursor line (press again for top/bottom) |
| C-M-f / C-M-b | Move forward / backward over a balanced expression (code) |
| C-M-a / C-M-e | Go to the start / end of the current function |
| C-u {number} | Repeat prefix: repeat the next command that many times (e.g. C-u 8 C-n) |
Editing Shortcuts
| Shortcut Key | Function |
|---|---|
| C-d | Delete the character after the cursor |
| Backspace (DEL) | Delete the character before the cursor |
| M-d | Kill (cut) the word after the cursor |
| M-Backspace | Kill the word before the cursor |
| C-k | Kill from the cursor to the end of the line |
| C-w | Kill the region (cut the selection) |
| M-w | Copy the region |
| C-y | Yank (paste) the last killed text |
| M-y (after C-y) | Cycle through the kill ring history |
| C-Space (or C-@) | Set the mark (start selecting / set a return point) |
| C-x C-x | Exchange the cursor and the mark |
| C-t | Transpose two characters |
| M-t | Transpose two words |
| C-x C-t | Transpose two lines |
| M-u / M-l / M-c | Uppercase / lowercase / Capitalize the word |
| C-o | Open a blank line after the cursor |
| M-^ | Join this line to the previous line |
| M-/ | Complete the word dynamically (from words in open buffers) |
| M-q | Fill (re-wrap) the paragraph |
| C-M-\ | Indent the region |
| M-$ | Run spell checking on the word (ispell) |
Search, Replace and Macros Shortcuts
| Shortcut Key | Function |
|---|---|
| C-s | Incremental search forward (repeat C-s for the next match) |
| C-r | Incremental search backward |
| C-M-s / C-M-r | Incremental regular-expression search forward / backward |
| M-% | Query Replace (confirm each replacement with y/n) |
| C-M-% | Query Replace using a regular expression |
| C-x ( | Start recording a keyboard macro |
| C-x ) | Stop recording the macro |
| C-x e | Execute the last recorded macro (repeat e to run again) |
| C-x 2 | Split the window horizontally (one below the other) |
| C-x 3 | Split the window vertically (side by side) |
| C-x o | Move to the other window |
| C-x 0 | Delete the current window |
| C-x 1 | Delete all other windows (keep only this one) |
| C-x 4 b | Show a buffer in another window |
| C-x 5 2 | Create a new frame (window in the OS sense) |
| C-x 5 0 | Delete the current frame |
| C-x 5 f | Open a file in a new frame |
Tips for Emacs Learners
Three ideas unlock Emacs. First, C-g cancels anything — a stuck command, a long search, a half-typed shortcut. Second, everything has a name: if you know a command's name, M-x runs it, and C-h a finds commands by keyword. Third, the kill ring is smarter than a clipboard: every cut is kept, C-y pastes the newest, and M-y cycles back through everything you cut before.
Frequently Asked Questions
How do I open and save a file in Emacs?
C-x C-f opens a file (type the path and Enter). C-x C-s saves the current buffer; C-x C-w writes it to a new name.
How do I exit Emacs?
C-x C-c. If buffers have unsaved changes, Emacs asks about each one before closing.
What does C-g do in Emacs?
C-g is the universal cancel: it aborts the current command, stops an incremental search and clears a stuck prefix — press it whenever Emacs seems to be waiting for something.
How do I select text in Emacs?
Press C-Space to set the mark, then move the cursor — the text between the mark and the cursor is the selected region, ready for C-w (cut) or M-w (copy).
By Umar Farooq, Tech Know.
0 Comments