GNU Emacs Reference

Editing commands, navigation, and customization.

GNU Emacs Reference

A practical guide to the Emacs operating model, commands, editing, discovery, programming tools, and configuration.

Updated 2026-07-22

Emacs Mental Model

Emacs is a programmable environment built around buffers and commands. A file is displayed through a buffer, a buffer is displayed in one or more windows, and windows belong to graphical or terminal frames.

The cursor position is called point. The mark stores another position. When point and mark delimit active text, that text is the region. Most editing commands operate at point, on the region, or on a syntactic unit determined by the active mode.

ConceptMeaning
FrameA top-level graphical or terminal Emacs display
WindowAn area of a frame displaying one buffer
BufferAn editable in-memory object that may or may not visit a file
FilePersistent data that a buffer can visit and save
PointThe current editing position
MarkA saved position used with point to define the region
RegionText between point and mark
CommandAn interactive Emacs Lisp function
ModeA keymap and behavior set active in a buffer

Keys and Commands

Emacs documentation uses C- for Control, M- for Meta, S- for Shift, RET for Return, SPC for Space, TAB for Tab, and DEL for Backspace. Meta is normally Alt or Option; pressing Escape before a key can also enter a Meta key.

A key sequence invokes a named command. Prefix keys such as C-x, C-c, and C-h begin larger keymaps rather than immediately performing an operation. M-x invokes a command by its name, which makes every interactive command accessible even when it has no key binding.

InputCommandPurpose
M-xexecute-extended-commandRun an interactive command by name
C-gkeyboard-quitCancel the current command
C-uuniversal-argumentSupply or build a prefix argument
M-5digit-argumentSupply numeric argument 5
C-xControl-X-prefixBegin the general C-x command map
C-hhelp-commandBegin the help command map

Major and Minor Modes

Every buffer has one major mode that defines its primary editing behavior. A buffer can also have any number of minor modes that add focused features such as automatic filling, syntax checking, or visual line wrapping.

Modes contribute key bindings, menus, syntax rules, indentation, font locking, and hooks. The mode line shows the active major mode and usually abbreviates active minor modes.

CommandPurpose
C-h mDescribe the active major and minor modes
M-x normal-modeRecompute the appropriate major and local modes
M-x fundamental-modeUse the minimal built-in major mode
M-x text-modeUse the general mode for human-readable text
M-x auto-fill-modeToggle automatic line filling
M-x display-line-numbers-modeToggle line numbers in the buffer
CSS ;; Run a function whenever text-mode starts. (add-hook 'text-mode-hook #'visual-line-mode)

Help and Discovery

Emacs is designed to explain its current state. Help commands inspect the exact running command, variable, keymap, and mode rather than requiring you to memorize a static configuration.

When a key behaves unexpectedly, describe the key and inspect the active modes. When you know the desired action but not its name, use apropos or search the Info manual.

KeyCommandPurpose
C-h k KEYdescribe-keyDescribe the command bound to KEY
C-h c KEYdescribe-key-brieflyShow only the command name
C-h f NAMEdescribe-functionDescribe a Lisp function
C-h v NAMEdescribe-variableDescribe a variable and its value
C-h x NAMEdescribe-commandDescribe an interactive command
C-h mdescribe-modeDescribe active modes and local bindings
C-h bdescribe-bindingsList all active bindings
C-h a TOPICapropos-commandFind matching commands
C-h w NAMEwhere-isFind keys bound to a command
C-h lview-lossageShow recent input events
C-h iinfoOpen the Info documentation browser
C-h rinfo-emacs-manualOpen the Emacs manual

Files and Buffers

Visiting a file creates or reuses a buffer whose contents correspond to that file. Editing changes the buffer; saving writes those changes to storage. Non-file buffers hold help, process output, messages, directories, or temporary text.

Buffer names and file names are related but distinct. Two files with the same base name receive distinct buffer names, and a buffer can be renamed without renaming its file.

KeyCommandPurpose
C-x C-ffind-fileVisit or create a file
C-x C-ssave-bufferSave the current buffer
C-x ssave-some-buffersOffer to save modified buffers
C-x C-wwrite-fileWrite the buffer to another file
C-x bswitch-to-bufferSwitch buffers
C-x C-blist-buffersDisplay the buffer list
C-x kkill-bufferKill a buffer
M-x revert-bufferrevert-bufferReplace the buffer with its stored contents
M-x rename-bufferrename-bufferChange the buffer name only

Windows, Frames, and Tabs

An Emacs window is a pane inside a frame, not an operating-system window. Multiple windows can show the same buffer at different positions, and display commands choose where buffers appear without changing the buffer itself.

Frames are top-level displays. Tab bars store reusable window configurations within a frame; they do not replace buffers.

KeyCommandPurpose
C-x 0delete-windowDelete the selected window
C-x 1delete-other-windowsKeep only the selected window
C-x 2split-window-belowSplit below
C-x 3split-window-rightSplit to the right
C-x oother-windowSelect another window
C-x 4 ffind-file-other-windowVisit a file in another window
C-x 5 2make-frame-commandCreate a frame
C-x 5 0delete-frameDelete the selected frame
C-x t 2tab-newCreate a tab-bar tab
C-x t otab-nextSelect the next tab

Editing, Killing, Yanking, and Undo

Deletion removes text without normally saving it. Killing removes text and records it in the kill ring. Consecutive kill commands can append to one kill-ring entry, allowing larger units to be assembled and yanked later.

Yanking inserts a kill-ring entry. Immediately following a yank with M-y rotates through older entries. Emacs undo records buffer changes as a sequence and can itself be interrupted and traversed.

KeyCommandPurpose
DEL / C-ddelete-backward-char / delete-charDelete a character
M-DEL / M-dbackward-kill-word / kill-wordKill a word
C-kkill-lineKill to the end of the line
C-wkill-regionKill the region
M-wkill-ring-saveCopy the region to the kill ring
C-yyankInsert the newest kill
M-yyank-popReplace the preceding yank with an older kill
C-x u / C-_ / C-/undoUndo changes
M-qfill-paragraphReflow a paragraph
M-;comment-dwimInsert, align, or remove a comment

Point, Mark, Region, and Narrowing

C-SPC records the current point as the mark. Moving point then creates a region. Transient Mark mode visually highlights active regions and lets region-aware commands distinguish active selections from inactive marks.

Emacs keeps a mark ring, so previous marks can be revisited. Narrowing temporarily restricts editing and display to part of a buffer; widening restores the accessible portion.

KeyCommandPurpose
C-SPCset-mark-commandSet or activate the mark
C-x C-xexchange-point-and-markExchange point and mark
C-u C-SPCset-mark-commandJump through earlier marks
C-x hmark-whole-bufferSelect the whole buffer
M-hmark-paragraphSelect a paragraph
C-M-hmark-defunSelect a definition
C-x n nnarrow-to-regionRestrict access to the region
C-x n wwidenRestore the full buffer

Search, Replace, and Regular Expressions

Incremental search updates the match as the search string is typed. Repeating the search key moves to another match, RET accepts the location, and C-g backs out or cancels.

Query replace asks before each replacement. Regular-expression variants use Emacs regular-expression syntax, whose escaping can differ from PCRE, JavaScript, and shell tools.

KeyCommandPurpose
C-s / C-risearch-forward / isearch-backwardIncremental literal search
C-M-s / C-M-risearch-forward-regexp / isearch-backward-regexpIncremental regexp search
M-%query-replaceConfirm replacements of a string
C-M-%query-replace-regexpConfirm regexp replacements
M-s ooccurList lines matching a regexp
M-x grepgrepRun grep and make results navigable
M-g n / M-g pnext-error / previous-errorMove through result locations
Query keyEffect
y / SPCReplace this match
n / DELSkip this match
!Replace all remaining matches
.Replace this match and exit
q / RETExit query replace
C-rEnter a recursive edit at this match

Minibuffer, Completion, and History

The minibuffer reads command arguments such as file names, buffers, commands, variables, and search patterns. Its completion category determines which candidates and matching rules apply.

Minibuffer histories are usually separate by argument type. Reusing history is often faster and safer than retyping a path or command.

KeyPurpose
TABComplete as far as possible or show candidates
SPCComplete a word when the active completion permits it
?Display completion candidates
M-p / M-nMove backward or forward through history
M-rSearch minibuffer history with a regexp
C-r / C-sSearch history incrementally
RETSubmit the current input
C-gAbort the minibuffer command

Registers and Rectangles

Registers are named single-character slots that can store text, positions, numbers, rectangles, window configurations, and other values. They are useful for deliberate temporary storage outside the kill ring.

Rectangle commands treat a region as columns spanning multiple lines. Rectangle Mark mode provides interactive rectangular selection and editing.

KeyCommandPurpose
C-x r s rcopy-to-registerCopy region text to register r
C-x r i rinsert-registerInsert register r
C-x r SPC rpoint-to-registerSave the current position
C-x r j rjump-to-registerJump to a stored position or configuration
C-x SPCrectangle-mark-modeStart a rectangular region
C-x r kkill-rectangleKill the selected rectangle
C-x r yyank-rectangleInsert the last killed rectangle
C-x r tstring-rectangleReplace each rectangle row with text

Dired

Dired is Emacs’s directory editor. A Dired buffer lists files and lets commands operate on the file at point, marked files, or files selected by a prefix argument.

Marking and flagging are different: marks select files for general commands, while deletion flags queue files for removal by x.

KeyCommandPurpose
C-x ddiredOpen a directory
n / pdired-next-line / dired-previous-lineMove between entries
RET / ^dired-find-file / dired-up-directoryVisit an entry or parent
m / u / Udired-mark / dired-unmark / dired-unmark-all-marksManage marks
d / xdired-flag-file-deletion / dired-do-flagged-deleteQueue and execute deletions
C / Rdired-do-copy / dired-do-renameCopy or rename files
Ddired-do-deleteDelete selected files after confirmation
+dired-create-directoryCreate a directory
grevert-bufferRefresh the directory listing
M-x wdired-change-to-wdired-modewdired-change-to-wdired-modeEdit file names as buffer text

Programming Tools

Emacs programming modes provide syntax-aware movement, indentation, comments, and commands. Xref supplies a common interface for definitions and references, project.el identifies projects, Compilation mode navigates diagnostics, and Eglot integrates language servers.

The available backend depends on the active major mode, project files, tags, language server, and installed external tools.

Key or commandCommandPurpose
M-.xref-find-definitionsFind a definition
M-?xref-find-referencesFind references
M-,xref-go-backReturn through xref history
C-M-a / C-M-ebeginning-of-defun / end-of-defunMove by definitions
C-M-hmark-defunMark a definition
C-M-\indent-regionIndent the region
M-x compilecompileRun a build or check command
M-g n / M-g pnext-error / previous-errorNavigate diagnostics
C-x p pproject-switch-projectSelect a known project
M-x egloteglotStart or connect to a language server

Shell and Process Integration

Emacs can invoke one-off commands, filter regions, and host interactive process buffers. shell-mode sends input through a shell process using comint, while term and ansi-term provide terminal-style character handling.

Process buffers are normal Emacs buffers with mode-specific bindings. Their working directory, environment, coding system, and process state affect command behavior.

Key or commandCommandPurpose
M-!shell-commandRun a command and display its output
M-&async-shell-commandRun a command asynchronously
M-|shell-command-on-regionSend the region through a command
M-x shellshellStart an interactive shell buffer
M-x termtermStart a terminal-emulation buffer
M-x eshelleshellStart the Emacs Lisp-based command shell
C-c C-c in comintcomint-interrupt-subjobInterrupt the active subprocess
C-c C-z in comintcomint-stop-subjobStop the active subprocess

Customization

Emacs behavior is controlled by variables, faces, hooks, and keymaps. The Customize interface discovers options and records selected values, while an init file can express configuration directly in Emacs Lisp.

Prefer documented customization variables and public functions over changing internal implementation details. Apply mode-specific behavior through hooks and mode keymaps rather than globally when possible.

CommandPurpose
M-x customizeOpen the top-level Customize UI
M-x customize-groupCustomize an option group
M-x customize-variableCustomize one variable
M-x customize-faceCustomize a face
M-x set-variableSet a variable for the current session
C-h vInspect a variable before changing it
CSS ;; Set an option through its supported customization API. (setq-default indent-tabs-mode nil) ;; Enable a feature in programming buffers. (add-hook 'prog-mode-hook #'display-line-numbers-mode) ;; Bind a global key to a command. (global-set-key (kbd "C-c f") #'find-file)

Init Files and Emacs Lisp

Emacs reads a user init file during normal startup. Common locations include ~/.emacs, ~/.emacs.d/init.el, and ~/.config/emacs/init.el; the exact selected file is available in the user-init-file variable.

Configuration is Emacs Lisp. Forms can be evaluated interactively while developing, then placed in the init file after their behavior is understood.

Key or expressionPurpose
C-x C-eEvaluate the Lisp form before point
M-:Read and evaluate a Lisp expression
M-x eval-bufferEvaluate the current buffer
M-x load-fileLoad an Emacs Lisp file
user-init-filePath of the loaded user init file
user-emacs-directoryBase directory for user Emacs data
CSS ;; Load optional configuration only after a feature is available. (with-eval-after-load 'dired (define-key dired-mode-map (kbd "C-c o") #'dired-display-file))

Packages

package.el installs and manages Emacs Lisp packages from configured archives. Emacs also ships many built-in libraries that can be loaded without installing an external package.

Archive contents are code executed with the user’s permissions. Review archive trust, package provenance, signatures, and update changes as part of normal dependency management.

CommandPurpose
M-x list-packagesBrowse available and installed packages
M-x package-refresh-contentsRefresh archive metadata
M-x package-installInstall a named package
M-x package-deleteRemove an installed package
C-h PDescribe an installed or available package
C-h pFind packages by topic keyword
CSS ;; Configure a package after it has loaded. (with-eval-after-load 'example-package (setq example-option t))

Server, Client, and Daemon Use

An Emacs server lets external emacsclient processes ask an existing Emacs instance to visit files or evaluate expressions. This avoids starting and initializing a new instance for each editor request.

A daemon starts without an initial graphical frame. Clients can create frames as needed. Server authentication data identifies the server and must remain protected.

CommandPurpose
M-x server-startStart a server in the current Emacs instance
emacs --daemonStart Emacs as a background daemon
emacsclient FILEVisit a file through the server
emacsclient -c FILECreate a graphical client frame
emacsclient -t FILEOpen a terminal client frame
C-x #Notify a waiting client that editing is finished

Recovery and Troubleshooting

Start by separating configuration problems from Emacs itself. A quick startup without the user init file and site file provides a clean comparison. Messages, command descriptions, active modes, and recent input usually reveal which component changed behavior.

Autosave data can recover edits after a crash. Backup files preserve earlier saved contents. Their names and locations depend on the active autosave and backup configuration.

CommandPurpose
emacs -QStart without init, site, or package initialization
emacs --debug-initShow a debugger for an init-file error
C-h eDisplay the Messages buffer
C-h lDisplay recent input events
C-h k KEYIdentify the command currently bound to a key
C-h mInspect modes affecting the current buffer
M-x toggle-debug-on-errorEnter the debugger when a Lisp error occurs
M-x recover-fileRecover a file from autosave data
M-x recover-sessionRecover files from an interrupted session

Description

Editing commands, navigation, and customization.

References

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies