Skip to content

Emacs Keybindings ​

This preset provides a modest set of Emacs keybindings for Master Key, covering the essential editing, navigation, selection, window management, search, and buffer manipulation features of Emacs.

Emacs uses modeless text insertion with a transient mark (ctrl+space), rich cursor and structural navigation (ctrl+f/b/n/p, alt+f/b, ctrl+a/e, alt+a/e, alt+{/}, ctrl+alt+f/b), universal argument prefixing (ctrl+u, alt+0..alt+9), kill-ring editing (ctrl+w, alt+w, ctrl+y, alt+y, ctrl+k), incremental search (ctrl+s, ctrl+r), and standard ctrl+x, ctrl+c, and ctrl+h command prefixes.

Contributions to improve the keybindings are welcome and can be submitted via a PR

Users can change what key is used for emacs M- by setting meta in [[define.val]]. (e.g. using source = "Emacs" in their own custom bindings). For example:

toml
[header]
version = "2.3.0"
source = "Emacs"

[[define.val]]
# use the window key for bindings with `M-` in emacs
meta = "win"

Cancellation & Help ​

(keyboard-quit) is the universal cancel command in Emacs. It cancels ongoing selections, deactivates mark, closes open widgets, and resets any pending prefixes or count arguments.

keynamedescriptionmode
quit / cancelcancel command / deactivate mark / dismiss widgetsemacs

Getting Help ​

Emacs bindings provides extensive contextual help.

keynamedescriptionmode
describe bindingsShow text documentation for keybindingsemacs
visual docShow visual documentation for keybindingsemacs
apropos commandSearch all available commandsemacs
describe variableOpen settings editoremacs
suggestShow all command suggestions.emacs

Mark & Region Management ​

The region in Emacs is defined between point (cursor) and mark. Pressing ctrl+space sets the mark variable (val.mark = true), causing subsequent cursor motions to extend the selected region. ctrl+x ctrl+x exchanges point and mark.

keynamedescriptionmode
set markSet mark at point and start selectingemacs
exchange point & markExchange cursor position with mark anchoremacs
mark whole bufferSelect entire bufferemacs
mark paragraphSelect current paragraphemacs
mark sexpSelect balanced expression or bracketed blockemacs
mark defunSelect surrounding function or blockemacs

Cursor Movement ​

Standard Emacs cursor movements operate character-by-character, line-by-line, and word-by-word. When mark is active, each motion extends the region.

keynamedescriptionmode
char →/←move cursor forward/backward one characteremacs
line ↓/↑move cursor down/up one lineemacs
line start/endmove cursor to beginning/end of lineemacs
first non-blankmove cursor to first non-blank character of lineemacs
word →/←move forward/backward by wordemacs
sentence ←/→move backward/forward by sentenceemacs
paragraph ←/→move backward/forward by paragraphemacs
buffer start/endmove cursor to beginning/end of bufferemacs
page ↓/↑scroll page down/upemacs
recenterrecenter window around cursor (recenter-top-bottom)emacs
goto lineGo to line numberemacs
next/prev errorNavigate to next/previous error or diagnosticemacs

Structural / shift+Expression Navigation (Paredit) ​

Structural motions allow jumping across balanced parentheses, brackets, and language expressions.

keynamedescriptionmode
sexp →/←move forward/backward across balanced expressionemacs
up listmove up and out of current bracketed structure (backward-up-list)emacs
down listmove down and into next bracketed structure (down-list)emacs
kill sexpkill forward balanced expression (kill-sexp)emacs

Killing & Yanking (Cut, Copy, Paste) ​

Text killed in Emacs is placed in the kill-ring (system clipboard). ctrl+w kills the active region, val.meta+w copies it without killing, ctrl+y yanks (pastes), and ctrl+k kills from point to end of line. Unlike Emacs, there is no consecutively killed lines are not appended to the same kill-ring element. (This would be easy to implement with a simple extension, but given the focus on this as a simple instructive example, this has been considered out of scope here).

keynamedescriptionmode
kill regionkill (cut) text in regionemacs
copy regioncopy region to kill ring without deleting (kill-ring-save)emacs
yankyank (paste) most recent kill from kill ringemacs

TODO: use better kill ring and accept that UX is different (update debug settings)

keynamedescriptionmode
yank popopen kill-ring historyemacs
yank nextgo to next item in kill-ring historyemacs
yank prevgo to next item in kill-ring historyemacs
kill linekill from cursor to end of line, or kill newline if at endemacs
kill whole linekill entire line including newlineemacs
delete chardelete character forward without adding to kill ringemacs
kill word →/←kill word forward / backwardemacs
kill sentencekill from point to end of sentenceemacs
zap to charkill text from point up to and including target characteremacs
delete blank linesdelete excess blank lines around pointemacs
delete spacesdelete all spaces and tabs around pointemacs
open lineinsert newline after cursor without moving pointemacs

Transposition ​

Transposition commands swap adjacent characters, words, or lines.

keynamedescriptionmode
transpose charstranspose two characters before and after cursoremacs
transpose wordstranspose two wordsemacs
transpose linestranspose current line with line aboveemacs

Case Transformations ​

Modify the case of words starting from point.

keynamedescriptionmode
upcase wordconvert word to UPPERCASE from point to end of wordemacs
downcase wordconvert word to lowercase from point to end of wordemacs
capitalize wordcapitalize next word (Title Case) from point to end of wordemacs

Indentation & Formatting ​

Indentation and code formatting commands.

keynamedescriptionmode
indentindent current line or selected region according to modeemacs
newline & indentinsert newline and auto-indent next lineemacs
indent regionre-indent region or format selection (indent-region)emacs
fill paragraphreflow and format current paragraph or comment (fill-paragraph)emacs
comment regiontoggle comment for selected lines or current lineemacs

Undo & Redo ​

Standard Emacs undo commands (ctrl+/, ctrl+_, ctrl+x u) and redo (val.meta+_).

keynamedescriptionmode
undo / redoundo / redo previous editemacs

Incremental search (ctrl+s forward, ctrl+r backward) and interactive query replace (val.meta+shift+5).

keynamedescriptionmode
isearch forward/backwardincremental search forward/backwardemacs
query replaceinteractively search and replace text (query-replace)emacs
regex replacesearch and replace using regular expressions (query-replace-regexp)emacs
occursearch pattern across workspace / project filesemacs

Prefix Arguments & Counts ​

Prefix arguments repeat commands a specified number of times. ctrl+u supplies a default multiplier of 4, while val.meta+0 through val.meta+9 supply exact numeric counts.

keynamedescriptionmode
universal argumentUniversal argument prefix (default 4x count multiplier)emacs
digit 0-9Add digit 0-9 to prefix argument countemacs

Buffers, Files & Windows ​

Emacs commands for finding files, saving buffers, switching buffers, and managing multi-window / split layout configurations.

keynamedescriptionmode
find fileOpen file by path or name (find-file)emacs
save bufferSave current file (save-buffer)emacs
write fileSave current file under a new name (write-file)emacs
save allSave all open modified buffers (save-some-buffers)emacs
switch bufferSwitch active editor to another buffer (switch-to-buffer)emacs
list buffersList all open editors and buffersemacs
kill bufferClose active editor buffer (kill-buffer)emacs
diredOpen file explorer / directory manager (dired)emacs
prev/next bufferSwitch to previous/next editor bufferemacs
delete windowClose active editor split group (delete-window)emacs
single windowClose all other editor split groups (delete-other-windows)emacs
split belowSplit editor horizontally below (split-window-below)emacs
split rightSplit editor vertically to the right (split-window-right)emacs
other windowNavigate cursor to other editor window group (other-window)emacs
balance windowsMake all editor windows equal width and heightemacs
find file otherOpen file in adjacent split groupemacs
kill buffer & windowClose buffer and split window groupemacs
close windowExit editor window (save-buffers-kill-terminal)emacs
zen modeToggle Zen full-screen distraction-free modeemacs

Code Navigation & LSP ​

Tag jumping and code intelligence commands.

keynamedescriptionmode
find definitionJump to definition of symbol at point (xref-find-definitions)emacs
pop tag markNavigate back to previous jump location (xref-go-back)emacs
tag forwardNavigate forward to next jump location (xref-go-forward)emacs
find referencesFind all references to symbol at point (xref-find-references)emacs
complete symbolTrigger autocomplete suggestionsemacs
hover infoShow documentation / type signature for symbol under pointemacs
rename symbolRefactor and rename symbol across projectemacs

Multi-Cursor Selection ​

Quickly add multiple cursors matching the selected word or find match.

keynamedescriptionmode
mark next matchAdd cursor at next matching occurrenceemacs
mark prev matchAdd cursor at previous matching occurrenceemacs
mark all matchesAdd cursors to all matching occurrences (mc/mark-all-like-this)emacs

Version Control ​

Basic version control commands (VC / Git).

keynamedescriptionmode
vc statusOpen source control / git panel (vc-dir)emacs
vc diffShow diff / file changes (vc-diff)emacs
vc annotateShow file blame / annotations (vc-annotate)emacs
vc logShow commit history log (vc-print-log)emacs

Commands & Shell Execution ​

Execute extended commands by name and launch terminal / shell commands.

keynamedescriptionmode
execute commandOpen command palette (execute-extended-command)emacs
shell commandToggle integrated terminal (shell-command)emacs

Keyboard Macros ​

Record and replay sequences of key commands.

keynamedescriptionmode
macro record / callStart, stop, and replay recorded keyboard macro; nested macros are not supportedemacs