Emacs Cheatsheet - Keybindings, Buffers & Org Mode
Emacs is notorious for its 2000+ default commands, but you only need a small set daily. This reference groups file & buffers, movement/editing, search, windows, macros and Org-mode, and first demystifies the C=Ctrl, M=Alt/Meta prefix notation, then the chording of C-x C-s style sequences. Learning it lowers the intimidation of the editor and moves editing into muscle memory. After reading you can open, edit and save files, wrangle buffers, and record a macro without touching the manual.
Typical Use Case
For people who want a single keybinding vocabulary spanning editing, code, Org-mode and personal knowledge management, especially in a keyboard-only or remote-shell environment. The sheet traces one thread: C-x prefixes manage files and buffers, C/M movement prefixes move by character and word, marking plus C-w/M-w/C-y forms the delete-kill-yank triangle, and incremental search with M-% closes the loop. Keyboard macros and Org-mode then turn the editor into a task tracker. C-g escapes any of it.
Files & Buffers 10
C-x C-fC-x C-sC-x C-wC-x bC-x kC-x C-cC-x 1C-x 2C-x 3C-x oCursor Movement 7
C-f / C-bM-f / M-bC-a / C-eC-n / C-pM-< / M->C-v / M-vM-g gEditing 12
C-SpaceC-wM-wC-yM-yC-dM-dC-kC-x C-uC-x C-lC-/C-gSearch & Replace 5
C-sC-rM-x replace-stringM-x replace-regexpM-%Windows & Bookmarks 5
C-x 0C-x ^C-x }C-x r mC-x r bKeyboard Macros 4
F3 / C-x (F4 / C-x )C-x eC-u 10 C-x eOrg-mode 5
* / ** / ***- / 1.C-c C-t<s TabC-c C-cParameter matrix
| Parameter | Effect | Example |
|---|---|---|
C-x C-f | Open a file | C-x C-f |
C-x C-s | Save the current buffer | C-x C-s |
C-x C-w | Save as a new file | C-x C-w |
C-x b / C-x k | Switch buffer / close buffer | C-x b |
C-x 1 / 2 / 3 | Keep only the current window / split vertically / split horizontally | C-x 3 |
C-x o | Switch to another window | C-x o |
C-f / C-b | Move forward / backward one character | C-f |
M-f / M-b | Move forward / backward one word | M-f |
C-a / C-e | Jump to beginning of line / end of line | C-e |
C-n / C-p | Next line / previous line | C-n |
M-< / M-> | Jump to beginning / end of file | M-> |
C-v / M-v | Scroll down / up one page | M-v |
M-g g | Jump to a specific line number | M-g g |
C-Space | Set the mark; moving the cursor selects the region | C-Space |
C-w / M-w | Cut the region / copy the region | M-w |
C-y / M-y | Paste / cycle through the paste history | M-y |
C-d / M-d | Delete the next character / next word | M-d |
C-k | Delete to end of line | C-k |
C-x C-u / C-x C-l | Convert the region to uppercase / lowercase | C-x C-u |
C-/ | Undo | C-/ |
C-g | Cancel the current operation—the universal exit key | C-g |
C-s / C-r | Incremental search forward / backward | C-r |
M-% | Interactive replace, confirming each occurrence | M-% |
M-x replace-string | Command-style string replacement | M-x replace-string |
M-x replace-regexp | Replace by regular expression | M-x replace-regexp |
C-x 0 / C-x ^ / C-x } | Delete the current window / increase window height / increase window width | C-x } |
C-x r m / C-x r b | Set a bookmark / jump to a bookmark | C-x r m |
F3 or C-x ( | Start recording a keyboard macro | F3 |
F4 or C-x ) | Stop recording | F4 |
C-x e | Run the last recorded macro | C-x e |
C-u 10 C-x e | Run the macro 10 times | C-u 10 C-x e |
* / ** / *** | Org-mode heading; the number of asterisks determines the level | ** second-level heading |
C-c C-t | Toggle the TODO state of the current entry | C-c C-t |
<s Tab | Insert a code block template | <s Tab |
C-c C-c | Confirm or execute a tag or code block | C-c C-c |
Common pitfalls
SymptomAfter typing M-x, some command does nothing and the minibuffer shows no prompt either
CauseThe Meta key was captured by the window manager or input method, so Emacs never received the M prefix
FixUse the ESC prefix instead of M (e.g. ESC x), or check whether the window manager's global shortcuts conflict with M-f and M-w
SymptomAfter cutting a large block you want a previous clipboard entry, but pasting still gives the one you just cut
CauseC-y by default only yanks the newest kill; M-y immediately after C-y is what walks back through history
FixPress M-y repeatedly to cycle through the kill ring until the entry you want appears
SymptomYou hit a long command by mistake and the screen is stuck halfway with no idea what to do
CauseMost Emacs commands are prefix-style and wait for further keys after the prefix is typed
FixJust press C-g to cancel the current operation and return to normal—this works for almost every stuck situation
SymptomAfter opening several splits you cannot find your previous editing position and switching windows is painful
CauseNo bookmark was used to record jump points, so you can only try C-x o one by one
FixSet a bookmark at frequently used jump points with C-x r m, then jump straight back with C-x r b
SymptomAs soon as you run a recorded macro it scrambles both the cursor and the content
CauseContext-dependent operations such as selection and jumps were also recorded, and the context differs when the macro runs
FixRecord only pure editing actions; right after running it, undo the bad result with C-/ and then adjust the macro
SymptomYou edited text in an Org file, but the outline structure and task status did not change with it
CauseHeading levels are expressed by the number of leading asterisks; manually indenting or deleting the leading asterisks degrades the line into a normal paragraph
FixMake sure heading asterisks start at the beginning of the line without indentation, and switch task status uniformly with C-c C-t instead of typing keywords by hand
SymptomYou wanted to select a passage but only cut a single word
CauseYou ran the cut without setting the mark first; Emacs cuts the region from the cursor to the target point
FixPress C-Space to set the mark, move the cursor to define the region, then press C-w to cut or M-w to copy
Troubleshooting
1Force your way back to a clean state when you do not know which command state you are in
C-gPressing C-g cancels any half-finished operation—the one thing most worth remembering in Emacs first.
2Select a passage of text to cut or copy
C-SpaceAfter setting the mark, move the cursor (C-f, M-f, C-n all work) to define the region, then follow with C-w or M-w.
3Switch quickly between several files without reopening them
C-x bPress Enter in the buffer list to switch; no need to run C-x C-f again.
4Batch-process repeated key sequences
F3Start recording, perform the operation once as usual, press F4 to stop, then press C-x e to replay the whole sequence.
5Run a repeated action ten times at once
C-u 10 C-x eA numeric prefix sets the repeat count first, then runs the macro; handy for batch-adding prefixes or processing lines one by one.
6Replace a string throughout the file, confirming each occurrence
M-%Interactive replace lets you choose replace, skip, or quit at each spot—ideal when you do not want to break the whole file in one go.
7Confirm and execute a code block in an Org file
C-c C-cAlso used to confirm tags; if not saved, Emacs prompts you to save the file first.
Command Examples
C-g is the universal escape
C-g // cancel the current operation (universal exit)C-g escapes nearly any "Emacs stopped listening" state: half-typed input in the minibuffer, an accidental recursive edit, a stuck macro recording. It does not undo anything, it only aborts the current interaction layer — so reach for it before restarting.
The mark-copy-paste loop
C-Space // set the mark (start the region)
M-w // copy the region
C-y // paste (yank)Move the point to the start, press C-Space, move to the end, then act. Cut with C-w rather than delete with C-d: the difference is that killed text lands in the kill ring and can be yanked back with C-y or M-y, while C-d really deletes it.
Interactive regexp replace: confirm case by case
M-% // interactive replace (confirm each occurrence)y replaces the current match, n skips, a replaces the rest, q quits, s opens a recursive edit. For renames or log-level changes where context decides, let Emacs ask rather than sed the whole file and roll back.
Output
Query replacing `old` with `new` (from beginning of buffer): (y/n/a/q/s/r .)
Record a macro and replay it
F3 // start recording a keyboard macro
C-x ( // start recording a keyboard macro
F4 // stop recording
C-x e // run the last recorded macro
C-u 10 C-x e // run the macro 10 timesA recorded macro freezes a sequence of edits into replayable keystrokes, ideal when the same change repeats dozens of times. C-u with a numeric prefix passes the repeat count, so after F4 you can bulk-apply with C-u N C-x e.
Output
F3 stop recording
Bookmarks for jumping around
C-x r m // set a bookmark
C-x r b // jump to a bookmarkWhen following one thread of logic across files, drop a bookmark with C-x r m and return to it from the list with C-x r b. It beats M-x goto-line because the position lives in the file and does not drift as lines are added or removed.
Split the window to compare two files
C-x 3 // split horizontally
C-x o // switch to another window
C-x 1 // keep only the current window
C-x 0 // delete the current windowAfter C-x 3, C-x o cycles between windows and C-x 1 closes everything except the current one. When you keep hopping between spots in one file, C-x ^ and C-x } resize the window instead of repeatedly splitting and killing it.
Common Pitfalls
- C-x C-s saves silently with no confirmation, and closing the window will not ask. Emacs does not guard unsaved buffers the way most editors do.
- Forget to end a recording (F4 / C-x )) and every following keystroke lands in the macro. C-g only escapes it; the history is already scrambled.
- C-w overwrites the top of the kill ring: cut twice in a row and the first snippet is pushed out of reach. Paste anything you care about elsewhere first.
- M-% offers no undo across the whole buffer — pressing a by mistake replaces every remaining match without a way back. Stay on y/n during confirmation.
- C-g in the minibuffer clears the current input; in a buffer it only aborts the current operation and does not undo the edits already made.
- C-x k closes a buffer without prompting, and unsaved changes are not recoverable from the session. You can often find the buffer again with C-x b, but do not rely on it.
Tips
- Emacs convention: C is Ctrl, M is Meta (Alt). C-x is the extended-command prefix.
- C-g is the universal cancel key; press it after any wrong operation to return to a normal state.
- C-Space sets a mark, then move the cursor to select a region; C-w cuts or M-w copies it.
FAQ
What exactly does C-g cancel, and why is it the first key to reach when you feel lost?
C-g is Emacs' universal abort: it breaks out of any submode or waiting prompt — an incremental C-s search, minibuffer input after M-x, a running C-x ( macro recording, a long-running command in progress. Since pressing it is never destructive (real deletion still needs an explicit C-w or C-d), treat it as a safe exit you can hit at any time. Inside the minibuffer, C-g is also how you abandon what you have typed instead of trying to undo your way out.
How do C-w, M-w and C-y divide the work between selection and the kill ring?
Emacs does not paste from a system clipboard: it keeps a kill ring of recent kills. Press C-Space to set the mark, move the cursor to form a selection, then C-w kills it (removing the text and pushing it onto the ring) while M-w copies it and leaves the text alone. C-y yanks the most recent kill, and M-y cycles back through older ones. So the reliable way to relocate a block is C-w, move the cursor, C-y — not C-w and then walk to the target. The ring is global, so kills stay available across buffers and files.
How do I record and replay a keyboard macro when the same edit must happen a hundred times?
Start recording with F3 or C-x (, perform the whole edit sequence once (go to line start, set the mark, select to end of line, delete, insert the replacement), and stop with F4 or C-x ). Replay with C-x e; to apply the macro 100 times type the numeric prefix first: C-u 100 C-x e. If you change your mind mid-recording, C-g aborts without leaving a half-built macro. Macros suit purely mechanical, branch-free repetitions; once the pattern needs a conditional, M-x replace-string or M-x replace-regexp is the better tool.
Should I split the frame (C-x 2, C-x 3) or just switch buffers (C-x b)?
They solve different problems. Buffer switching (C-x b) swaps the content of a single window, which is what you want when moving between a few files. Splitting keeps several buffers visible at once so you can watch a parser result or program output update while you edit another file. The window set: C-x 2 splits vertically, C-x 3 horizontally, C-x o moves to the other window, C-x 1 leaves only the current one, C-x 0 deletes it, and C-x ^ / C-x } grow the current window taller or wider. Bookmarks via C-x r m and C-x r b then jump you back to those positions quickly.
When should I reach for M-% instead of M-x replace-regexp?
It depends on how sure you are of the matches. M-x replace-string and M-x replace-regexp sweep the whole buffer and write immediately, which suits a clear, uniform pattern. M-% prompts you once per match — y to replace, n to skip, N to replace the rest, q to quit — so you can exclude the occasional hit that should stay. Reach for replace-regexp when the pattern needs metacharacters (quantifiers, character classes, anchors); for literal text replace-string is faster and safer. In either case, run a C-r search first to confirm the hit range.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us