Skip to content

Emacs Shortcuts

  • Main source is Absolute Beginners Guide to Emacs with pictures and key bindings, good plain language overview
  • Use modeline to check place in file: <file> line number:column top/bot/all/xx%
    • Top first line is visible
    • Bot last line is visible
    • All first and last line are visible
    • 45% relative position in the file
    • Format is same as vim ruler (in vim :help ruler)
NameShortcuts
Run any commandM-x
Run commands relevant to buffer modesM-S-X (M-X)
Find / Open filefind-file
Save bufferC-x C-s
HelpC-h C-h
Quit partial commandC-g
Exit emacsC-x C-c
Switch buffersC-x b
Switch buffers: List BuffersC-x C-b
Switch buffers: Cycle through buffersC-x right , C-x left
Quit read only bufferq
Personal and common major mode leader keyC-c
Reload screen, mode (many modes like magit, dashboard)g
NameShortcuts
proced: htop equivalent, list system processes and act on themproced
proced: Markm
Restart Emacsrestart-emacs
NameShortcuts
Update all packagesauto-package-update-now
Update all straight installed packagesstraight-pull-all

Frame (Modern Windows) Management and Buffers

Section titled “Frame (Modern Windows) Management and Buffers”
NameShortcuts
New frame (window)C-x 5 2
Close frame (window)C-x 5 0
Speedbar (like file, buffer explorer)speedbar
NameShortcuts
Split window horizontallyC-x 2
Split window verticallyC-x 3
Go to other windows (cycle through windows))C-x o
NameShortcuts
Indent region fn1C-M-\ or indent-region
Indent region rightCtrl + right arrow
Indent region leftCtrl + left arrow
Indent region with keysSelect region, C-x TAB, use arrows, ESC x 3
  • fn1 Indent region can be used to indent region to same column or “delete” an indent by reset the first item in the region to the desired indentation.

Select / Marking, Killing and Yanking Text

Section titled “Select / Marking, Killing and Yanking Text”
NameShortcuts
Mark / SelectC-SPC (Spacebar) to start/stop highlight
Mark - multiple select, region in rectangle, if in Evil, switch to EmacsC-x SPC or rectangle-mark-mode
Mark - paragraphmark-paragraph
Mark - select current paragraphM-h
Cut (kill marked) textSHIFT-DEL or C-w
Cut to end of current lineC-k
Copy (copy marked) textC-INSERT or M-w
Paste (yank text back)SHIFT-INSERT or C-y
Paste (using kill ring)M-y or M-Y (reverse direction)
Undo - redoC-/ or C-_
UndoC-M-_
Undo Multiple Modeundo-tree-mode
Kill word (delete word near cursor)M-d
Comment Region / Uncomment regionM-; / uncomment-region
Clear kill ring(setq kill-ring nil)
  • For undo in region, select/mark region and undo will be limited to the region, there are other operations like replace-string (search and replace) that work the same way

See also:

  1. Default isearch, occur

    Only matches characters, not regex unless using isearch-…-regex

    NameShortcuts
    Search in file isearchC-s or isearch-forward, C-s or isearch-backward
    Search in file isearch, cancelC-g
    Search in file isearch, enter at pointEnter
    Search in file isearch, enter beginning of search wordC-b
    Search in file isearch, repeat last searchC-s C-s or C-r C-r
    Search in file isearch regexC-M-s or isearch-forward-regex, C-M-r or isearch-backward-regex
    Search with search results occurM-s-o or occur
    Search in file isearch with occur for buffer with resultsC-s <search-text> M-s-o (while in isearch)
    Search and highlight in fileM-s h l or hi-lock-face-buffer
    Search and highlight in file, cancelM-s h u or hi-lock-unface-buffer aka unhighlight-regexp
  2. Find/Search and Replace

    NameShortcuts
    Search and replace with extra functionalityM-Shift-% or query replace or replace-string
    Find and replace search queryM-% or query-replace
    Find and replace search query from isearchC-s <search-text> M-% (while in isearch, can also work with isearch regex commands)
    Find and replace search query, previous queriesM-p
  3. Other packages

    Find and replace works for whole buffer or selected region

    NameShortcuts
    Search in fileM-x swiper or helm-swoop
    Find and replace - Close all file buffersprojectile-replace
    Find and replace - Close all file buffersdired-do-find-regexp-and-replace (Q) in dired in a directory or with marked files
    Find word -Search (backward)C-r or Backspace (aka DEL)
    Regexp “helper”M-x re-builder
NameShortcuts
Delete the character just before the cursor<DEL>
Delete the next character after the cursor, delete line on character before empty linesC-d
Kill the word immediately before the cursorM-<DEL>
Kill the next word after the cursorM-d
Kill from the cursor position to end of lineC-k
Kill to the end of the current sentenceM-k
  • Use abbrev-mode to auto expand abbreviations when they are typed

  • Combine abbreviations like:

    • Instead of typing “electromagnetic” type: eltr M-’ mgntc; and emacs will expand it to “electromagnetic”

Use various functions to convert region/words to all uppercase, lowercase or capitalize all words

NameShortcuts
Capitalize words in regionCapitlize-dwim
Upper case all words in regionupcase-dwim
Lower case all words in regiondowncase-dwim
  • Combine navigation commands with C-u + number plus the navigation command to move by that number (e.g. C-u 2 C-f to move forward 2 characters).
NameShortcuts
Move forward a characterC-f
Move backward a characterC-b
Move forward a wordM-f= or `C-arrow-key-left
Move backward a wordM-b` or =C-arrow-key-right
Move to next lineC-n
Move to previous lineC-p
Move to beginning of lineC-a or home
Move to end of lineC-e or end
Move to beginning of bufferM-< or =C-Home
Move to end of bufferM-> or =C-End
Move back to beginning of sentenceM-a
Move forward to end of sentenceM-e
Scroll upPage Up or C-v
Scroll up other windowM-Page Up
Scroll downPage Down M-v
Scroll down other windowM-Page Down
Increase font / text sizeC-x C-+ or text scale increase
Navigate on headings / code parts in buffercounsel-imenu or imenu / M-g i (Emacs 29)
Navigate on headingscounsel-outline
Switch to or restart ‘scratch’ bufferscratch-buffer
Center current line in bufferC-l
Center current line in buffer, then topC-l C-l

Justification, Margins, Fixed Width of Columns, Guide lines

Section titled “Justification, Margins, Fixed Width of Columns, Guide lines”

Source: Issue 001 - System Crafters - see Tips of the Week

NameShortcuts
Draw line in buffer where fill-column is setdisplay-fill-column-indicator-mode
Automatically wrap paragraph text to fit within the specified widthauto-fill-mode
Center a regioncenter-region
Reshapes a paragraph of text so that it fits under 80 columnsM-q or fill-paragraph
  • Set at where fill-column cuts off for display fill column indicator

Source: GNU Emacs Manual - Registers

Register is like a bookmark/saved text, position, window/frame configuration, and rectangle for later use. Register names are a single character like r.

NameShortcuts
Bookmark setC-x r m, bookmark-set
Bookmark: jump toC-x r b , bookmark-jump
Bookmark: list allC-x r l , list-bookmarks
Bookmark: save all to filebookmark-save
NameShortcuts
Register: View contents of named register “r”view-register RET r
Register: Record position of point in register “r”C-x r SPC r , point-to-register
Register: Go to register “r”, recall frameset, number, etc.C-x r j r , jump-to-register
Register: Copy region into register “r”C-x r s r , copy-to-register
Register: Insert (paste) from register “r”C-x r i r, insert-register
Register: Append region to register “r”append-to-register RET r
Register: Prepend region to register “r”prepend-to-register RET r
Register: Copy rectangle region to register “r”C-x r r r , copy-rectangle-to-register
Register: Insert rectangle region to register “r”C-x r i r , copy-rectangle-to-register
Register: Save window and frame configurationswindow-configuration-to-register
Register: Save frames and windows configurationsframeset-to-register
Register: Restore window/frame config (same as jump)C-x r j r , jump-to-register
Register: Store number in register “r”C-x r n r , number-to-register
Register: Increment number in register “r”C-x r + r , increment-register
Register: Save macro to register “r”C-x C-k x r , kmacro-to-register
Register: Execute keyboard macro in register “r”C-x r j r
  • Save file and buffer names in registers: (set-register r '(file . name))
NameShortcuts
Customize interfaceM-x customize
Activate text major modeM-x text-mode
Change margins for auto-fill-mode (auto line wrapping)C-x f
Set directory local variablesM-x add-dir-local-variable or use .dir-locals.el
  • Set directory local variables are useful for variables that only apply in a certain directory like with using projectile-test-cmd, setting file formatters and others
NameShortcuts
Record macroF3
Stop recording macroF4
Execute macroF4
Execute macro until end of file or errorC-0 F4
Name, save macroM-x kmacro-name-last-macro= (use a prefix like mp-)
Have Emacs generate Elisp for a macroM-x insert-kbd-macro
  • Tip: using insert-kbd=macro, save for use as an interactive function for repetitive use
NameShortcuts
HelpC-h
Help on featureC-h c
Help on commandC-h k
Help on function (describe-function)C-h f= - can drill into function’s cod
Help on variable (describe-variable)C-h v
Help on key bindings for current function/minibufferC-h b
Help Apropos (search command keyword)C-h a
Help Search - search all manualsinfo-apropos
Read manuals (aka info) for installed packagesC-h i
Open emacs manualC-h r
Help buffer - next / Previous page in Info buffern / p
NameShortcuts
Suspend Emacs temporarilyC-x C-z
Run emacs for first time on command lineemacs -q
Check for unbalanced parentheses in Lispcheck-parens=
NameShortcuts
Run elisp codeeval-expression or M-:
Evaluate the current elisp expressionC-x C-e or eval-last-sexp
Evaluate region or bufferC-c C-e or elisp-eval-region-or-buffer
NameShortcuts
Open shellM-x eshell
Open other shellM-x term
NameShortcuts
Line mode to navigate buffer independent of promptC-c C-j (on) / C-c C-k (off)
Access Emacs command promptC-x M-x= (my binding is F1)
Scroll one screen at a timeS-Page Up/Down
Send C-c SIGINT to terminalC-c C-c or C-g C-c C-c to quit any keyboard commands and send SIGINT)
  • Run shell command asynchronously: M-& - show command results in separate buffer
NameShortcuts
Open web browsereww
Open system browser on current file / urlbrowse-url-of-file, browse-url
Open html file, from eww or other browsereww-open-file
Reader mode to remove nav headers and othersR, eww-readable
Copy text from eww with org mode linksorg-eww-copy-for-org-mode
NameShortcuts
At suggestions at cursorcompletion-at-point
Flycheck, check LSP, linters, checkers enabledC-c ! v or flycheck-verify-setup
Flycheck, LSP, linters, Errors ListC-c ! l or flycheck-list-errors
LSP Mode - Leader keyC-c l
LSP Mode - Find referencesC-c l g r
LSP Mode - Find definitionsC-c l g g
LSP Mode - Refactor like renameC-c l r
LSP Mode - Flymake tracks problems in fileflymake-show-buffer-diagnostics
LSP Mode - Code formattingC-c l = == or TAB
LSP Mode - Display symbols with treemacsM-x lsp-treemacs-symbols
LSP, Update LSP serversM-x lsp-update-servers
LSP, Update LSP specific serverM-x lsp-update-server
Spelling - Flyspell autocorrect wordC-M-i
Spelling - Flyspell suggest words for correctionC-c-$
Compile, run async shell command, output bufferM-x compile
Compile, go to next error and fileC-x `
Compile, run last compile command againM-x recompile

Source: ediff Basics - Prot

  • Function to see difference between files side by side
  • When going through diffs, see ediff control panel for description of differences
  • Buffers are normal buffers and can be edited
  • ediff can be used in magit status, when selecting commits
NameShortcuts
Diff on Filesediff-files
Diff on 3 Filesediff3-files
Diff on buffersediff-buffers
Diff on buffers, ediff help?
Diff, ediff move difference at point in file A to Ba
Diff, ediff move difference at point in file B to Ab
Diff, ediff next, previous differencen, N
Diff, ediff diff output differenceD
Diff, ediff quitq
NameShortcuts
Recover file from autosaveM-x recover-file
NameShortcuts
List all fontsM-x list-faces-display
NameShortcuts
Convert strokes to commands, see more withstrokes-help

Supports remote systems and docker, podman, and kubernetes connection methods

NameShortcuts
Play game, pongM-x pong
Play game, snakeM-x snake
Play game, tetrisM-x tetris
Psychotherapy with ElizaM-x doctor