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.

Dev Tools·48 commands·Last updated 2026-07-21

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-f
Open file
C-x C-s
Save current buffer
C-x C-w
Save as
C-x b
Switch buffer
C-x k
Close buffer
C-x C-c
Quit Emacs
C-x 1
Keep only current window
C-x 2
Split window vertically
C-x 3
Split window horizontally
C-x o
Switch to other window

Cursor Movement 7

C-f / C-b
Forward / backward one char
M-f / M-b
Forward / backward one word
C-a / C-e
Beginning / end of line
C-n / C-p
Next / previous line
M-< / M->
Beginning / end of file
C-v / M-v
Scroll down / up
M-g g
Go to a specific line

Editing 12

C-Space
Set mark (start selection)
C-w
Cut (kill) region
M-w
Copy region
C-y
Paste (yank)
M-y
Cycle paste history
C-d
Delete next char
M-d
Delete next word
C-k
Delete to end of line
C-x C-u
Uppercase
C-x C-l
Lowercase
C-/
Undo
C-g
Cancel current operation (universal quit)

Windows & Bookmarks 5

C-x 0
Delete current window
C-x ^
Increase current window height
C-x }
Increase current window width
C-x r m
Set bookmark
C-x r b
Jump to bookmark

Keyboard Macros 4

F3 / C-x (
Start recording keyboard macro
F4 / C-x )
Stop recording
C-x e
Execute last recorded macro
C-u 10 C-x e
Execute macro 10 times

Org-mode 5

* / ** / ***
Heading level (star count sets level)
- / 1.
Unordered / ordered list
C-c C-t
Toggle TODO state
<s Tab
Insert code block template
C-c C-c
Confirm/execute tag or code block

Parameter matrix

ParameterEffectExample
C-x C-fOpen a fileC-x C-f
C-x C-sSave the current bufferC-x C-s
C-x C-wSave as a new fileC-x C-w
C-x b / C-x kSwitch buffer / close bufferC-x b
C-x 1 / 2 / 3Keep only the current window / split vertically / split horizontallyC-x 3
C-x oSwitch to another windowC-x o
C-f / C-bMove forward / backward one characterC-f
M-f / M-bMove forward / backward one wordM-f
C-a / C-eJump to beginning of line / end of lineC-e
C-n / C-pNext line / previous lineC-n
M-< / M->Jump to beginning / end of fileM->
C-v / M-vScroll down / up one pageM-v
M-g gJump to a specific line numberM-g g
C-SpaceSet the mark; moving the cursor selects the regionC-Space
C-w / M-wCut the region / copy the regionM-w
C-y / M-yPaste / cycle through the paste historyM-y
C-d / M-dDelete the next character / next wordM-d
C-kDelete to end of lineC-k
C-x C-u / C-x C-lConvert the region to uppercase / lowercaseC-x C-u
C-/UndoC-/
C-gCancel the current operation—the universal exit keyC-g
C-s / C-rIncremental search forward / backwardC-r
M-%Interactive replace, confirming each occurrenceM-%
M-x replace-stringCommand-style string replacementM-x replace-string
M-x replace-regexpReplace by regular expressionM-x replace-regexp
C-x 0 / C-x ^ / C-x }Delete the current window / increase window height / increase window widthC-x }
C-x r m / C-x r bSet a bookmark / jump to a bookmarkC-x r m
F3 or C-x (Start recording a keyboard macroF3
F4 or C-x )Stop recordingF4
C-x eRun the last recorded macroC-x e
C-u 10 C-x eRun the macro 10 timesC-u 10 C-x e
* / ** / ***Org-mode heading; the number of asterisks determines the level** second-level heading
C-c C-tToggle the TODO state of the current entryC-c C-t
<s TabInsert a code block template<s Tab
C-c C-cConfirm or execute a tag or code blockC-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

  1. 1Force your way back to a clean state when you do not know which command state you are in

    C-g

    Pressing C-g cancels any half-finished operation—the one thing most worth remembering in Emacs first.

  2. 2Select a passage of text to cut or copy

    C-Space

    After 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.

  3. 3Switch quickly between several files without reopening them

    C-x b

    Press Enter in the buffer list to switch; no need to run C-x C-f again.

  4. 4Batch-process repeated key sequences

    F3

    Start recording, perform the operation once as usual, press F4 to stop, then press C-x e to replay the whole sequence.

  5. 5Run a repeated action ten times at once

    C-u 10 C-x e

    A numeric prefix sets the repeat count first, then runs the macro; handy for batch-adding prefixes or processing lines one by one.

  6. 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.

  7. 7Confirm and execute a code block in an Org file

    C-c C-c

    Also 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 times

A 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 bookmark

When 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 window

After 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