Emacs Cheatsheet
DevOps
emacstext-editorterminallisporg-modesysadmin
Emacs Cheatsheet
GNU Emacs is a Lisp-based, infinitely extensible editor. It's not just a text editor — it's a complete computing environment. Key convention: `C-` = Ctrl, `M-` = Alt (Meta).
Emacs
GNU Emacs is a Lisp-based, infinitely extensible editor. It's not just a text editor — it's a complete computing environment. Key convention: C- = Ctrl, M- = Alt (Meta).
Basic Navigation
| Key | Action | Mnemonic |
|---|---|---|
C-f | Forward one character | Forward |
C-b | Back one character | Back |
C-n | Next line | Next |
C-p | Previous line | Previous |
C-a | Beginning of line | Beginning of alphabet |
C-e | End of line | End |
M-f | Forward one word | Meta Forward |
M-b | Back one word | Meta Back |
M-a | Beginning of sentence | Meta Beginning |
M-e | End of sentence | Meta End |
C-v | Page down | View |
M-v | Page up | Meta View |
C-l | Re-center cursor on screen | Line |
M-< | Beginning of buffer | Meta Less-than |
M-> | End of buffer | Meta Greater-than |
C-g | Cancel/quit current command | Go away |
File & Buffer Management
# Files
C-x C-f # find (open) file
C-x C-s # save file
C-x C-w # write as (save as)
C-x C-c # exit Emacs
C-x k # kill (close) current buffer
C-x C-j # open Dired (file manager)
# Buffers
C-x b # switch buffer (with auto-complete)
C-x C-b # list all buffers
C-x <left> # previous buffer
C-x <right> # next buffer
C-x k # kill buffer
Editing
| Key | Action |
|---|---|
Backspace | Delete previous character |
C-d | Delete next character |
M-Backspace | Delete previous word |
M-d | Delete next word |
C-k | Kill to end of line (cut) |
M-k | Kill to end of sentence |
C-w | Kill region (cut selection) |
M-w | Copy region |
C-y | Yank (paste) |
M-y | Cycle through kill ring after yank |
C-/ or C-x u | Undo |
C-Shift-/ or C-x C-Shift-u | Redo (Emacs 28+) |
C-Space | Set mark (begin selection) |
C-x h | Select entire buffer |
C-t | Transpose two characters |
M-t | Transpose two words |
C-x C-t | Transpose two lines |
M-c | Capitalize word |
M-u | Uppercase word |
M-l | Lowercase word |
M-q | Fill (reflow) paragraph |
Search & Replace
# Incremental search
C-s # search forward (incremental)
C-r # search backward (incremental)
# While searching:
# C-s again = jump to next match
# C-r again = jump to previous match
# C-g = cancel search
# Non-incremental search
M-C-s # search forward with regex
M-C-r # search backward with regex
# Replace
M-% # query-replace (prompted replace)
# y = replace, n = skip, ! = replace all, q = quit
# Replace with regex
C-M-% # query-replace-regexp
Kill & Yank Ring
# The kill ring is Emacs's multi-item clipboard
C-k # kill (cut) line from cursor to end
C-k C-k # kill entire line (including newline)
C-w # kill region (cut selection)
M-w # copy region (without killing)
C-y # yank (paste most recent kill)
M-y # cycle kill ring — press repeatedly after C-y
# Example: paste something from 3 cuts ago
C-y M-y M-y M-y
Window Management
# Split windows
C-x 2 # split horizontally
C-x 3 # split vertically
C-x 1 # close all other windows
C-x 0 # close current window
# Navigate between windows
C-x o # switch to next window
# Resize windows
C-x ^ # grow window height
C-x } # grow window width
C-x { # shrink window width
C-x + # balance all windows
Org-Mode Basics
Org-Mode is Emacs's killer app — an outline-based document and task management system built in.
# Open an Org file
C-x C-f todo.org
# Outline navigation
Tab # cycle visibility (fold/unfold subtree)
S-Tab # cycle global visibility
C-c C-n # next heading
C-c C-p # previous heading
C-c C-f # forward heading (same level)
C-c C-b # backward heading (same level)
C-c C-u # go to parent heading
# Structure editing
M-Enter # new heading/item below
M-S-Enter # new heading (same level as parent)
M-Left/Right # promote/demote subtree
M-S-Left/Right # promote/demote subtree with children
M-Up/Down # move subtree up/down
# Todo lists
C-c C-t # cycle todo state (TODO → DONE → TODO)
S-Right/Left # cycle through todo keywords
# Tables (built-in spreadsheet)
C-c | # create or convert to table
Tab # move to next cell / re-align
S-Tab # move to previous cell
M-Left/Right # move column
M-Up/Down # move row
C-c - # insert horizontal line
C-c Enter # insert row below
C-c C-c # recalculate table formulas
# Links
C-c C-l # insert/edit link
C-c C-o # open link at point
# Export
C-c C-e # export dispatcher
# h h = export to HTML
# l p = export to PDF (via LaTeX)
# l o = export to ODT
# m m = export to Markdown
Practical Org-Mode Example
# Create a task list
* Project Alpha
** TODO Research competitor features
SCHEDULED: <2026-04-25>
** TODO Design API schema
SCHEDULED: <2026-04-28>
** DONE Write initial documentation
CLOSED: [2026-04-18 Sat]
# A simple table with formula
| Item | Qty | Price | Total |
|----------+-----+-------+-------|
| Widget | 3 | 10 | 30 |
| Gadget | 2 | 25 | 50 |
| Doohickey| 1 | 15 | 15 |
|----------+-----+-------+-------|
| Total | 6 | | 95 |
#+TBLFM: @5$4=vsum(@2$4..@4$4)
.emacs / emacs.d Init
# ~/.emacs.d/init.el — modern Emacs configuration
;; Package management
(require 'package)
(setq package-archives '(("melpa" . "https://melpa.org/packages/")
("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Use-package for clean config (built-in since Emacs 29)
(setq use-package-always-ensure t)
;; UI
(tool-bar-mode -1) ; hide toolbar
(menu-bar-mode -1) ; hide menubar
(scroll-bar-mode -1) ; hide scrollbar
(column-number-mode 1) ; show column number
(global-display-line-numbers-mode 1) ; show line numbers
(show-paren-mode 1) ; highlight matching parens
(electric-pair-mode 1) ; auto-close brackets
;; Theme
(use-package doom-themes
:config
(setq doom-themes-enable-bold t
doom-themes-enable-italic t)
(load-theme 'doom-one t))
;; Editing
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
(setq-default fill-column 80)
(global-auto-revert-mode t) ; auto-reload changed files
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save/" t)))
;; Key bindings
(global-set-key (kbd "C-<tab>") 'other-window)
(global-set-key (kbd "M-/") 'company-complete)
(global-set-key (kbd "C-c g") 'magit-status)
(global-set-key (kbd "C-x k") 'kill-current-buffer)
Common Packages
Magit (Git Interface)
# Install
M-x package-install RET magit RET
# Usage
C-x g # open Magit status buffer
# In Magit status:
# s = stage file
# u = unstage file
# c c = commit (opens commit message buffer)
# C-c C-c = finish commit
# P p = push
# F p = pull
# l l = log
# d d = diff
# z s = stash
# b b = checkout branch
# Tab = expand/collapse section
# q = quit Magit
Company (Auto-Completion)
# Install
M-x package-install RET company RET
# Configuration (add to init.el)
(use-package company
:hook (prog-mode . company-mode)
:config
(setq company-minimum-prefix-length 1
company-idle-delay 0.0)
(global-company-mode 1))
# Usage (in prog-mode, completions appear automatically):
M-/ # trigger completion manually
C-n / C-p # navigate completion candidates
Tab # accept completion
Flycheck (Syntax Checking)
# Install
M-x package-install RET flycheck RET
# Configuration (add to init.el)
(use-package flycheck
:init (global-flycheck-mode))
# Usage:
# Flycheck runs automatically in supported modes
C-c ! l # list errors
C-c ! n # jump to next error
C-c ! p # jump to previous error
C-c ! v # verify Flycheck setup
C-c ! s # set checker
Key Chord Reference
Essential Survival Keys
| Key | Action |
|---|---|
C-g | Cancel any command |
C-x C-c | Quit Emacs |
C-x u or C-/ | Undo |
C-x C-f | Open file |
C-x C-s | Save file |
C-x C-b | List buffers |
C-x b | Switch buffer |
Movement
| Key | Action |
|---|---|
C-f / C-b | Char forward / back |
C-n / C-p | Line down / up |
C-a / C-e | Line start / end |
M-f / M-b | Word forward / back |
M-< / M-> | Buffer start / end |
C-v / M-v | Page down / up |
Killing & Yanking
| Key | Action |
|---|---|
C-k | Kill line (cut to end) |
C-w | Kill region (cut selection) |
M-w | Copy region |
C-y | Yank (paste) |
M-y | Cycle kill ring |
Window & Buffer
| Key | Action |
|---|---|
C-x 2 | Split horizontal |
C-x 3 | Split vertical |
C-x 1 | Single window |
C-x o | Other window |
C-x b | Switch buffer |
C-x k | Kill buffer |
Search & Replace
| Key | Action |
|---|---|
C-s / C-r | Search forward / backward |
M-% | Query replace |
C-M-% | Query replace regex |
Help System
C-h f # describe function
C-h v # describe variable
C-h k # describe key binding
C-h m # describe current mode's bindings
C-h a # apropos (search all commands by keyword)
C-h t # built-in Emacs tutorial
C-h i # Info manual browser
Tips
Install Packages from MELPA
```bash
Add MELPA to init.el (if not already present)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
Then in Emacs:
M-x package-refresh-contents RET
M-x package-install RET
Next Steps
- Bash CLI Tools Cheat Sheet — Unix command-line utilities for power users
- Git CLI Cheat Sheet — Version control commands and workflows
- Vim Cheat Sheet — Powerful modal editor for rapid editing
- Nano Cheat Sheet — Simple terminal editor for quick edits