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:
[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.
| key | name | description | mode |
|---|---|---|---|
| quit / cancel | cancel command / deactivate mark / dismiss widgets | emacs |
Getting Help
Emacs bindings provides extensive contextual help.
| key | name | description | mode |
|---|---|---|---|
| describe bindings | Show text documentation for keybindings | emacs | |
| visual doc | Show visual documentation for keybindings | emacs | |
| apropos command | Search all available commands | emacs | |
| describe variable | Open settings editor | emacs | |
| suggest | Show 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.
| key | name | description | mode |
|---|---|---|---|
| set mark | Set mark at point and start selecting | emacs | |
| exchange point & mark | Exchange cursor position with mark anchor | emacs | |
| mark whole buffer | Select entire buffer | emacs | |
| mark paragraph | Select current paragraph | emacs | |
| mark sexp | Select balanced expression or bracketed block | emacs | |
| mark defun | Select surrounding function or block | emacs |
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.
| key | name | description | mode |
|---|---|---|---|
| char →/← | move cursor forward/backward one character | emacs | |
| line ↓/↑ | move cursor down/up one line | emacs | |
| line start/end | move cursor to beginning/end of line | emacs | |
| first non-blank | move cursor to first non-blank character of line | emacs | |
| word →/← | move forward/backward by word | emacs | |
| sentence ←/→ | move backward/forward by sentence | emacs | |
| paragraph ←/→ | move backward/forward by paragraph | emacs | |
| buffer start/end | move cursor to beginning/end of buffer | emacs | |
| page ↓/↑ | scroll page down/up | emacs | |
| recenter | recenter window around cursor (recenter-top-bottom) | emacs | |
| goto line | Go to line number | emacs | |
| next/prev error | Navigate to next/previous error or diagnostic | emacs |
Structural / shift+Expression Navigation (Paredit)
Structural motions allow jumping across balanced parentheses, brackets, and language expressions.
| key | name | description | mode |
|---|---|---|---|
| sexp →/← | move forward/backward across balanced expression | emacs | |
| up list | move up and out of current bracketed structure (backward-up-list) | emacs | |
| down list | move down and into next bracketed structure (down-list) | emacs | |
| kill sexp | kill 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).
| key | name | description | mode |
|---|---|---|---|
| kill region | kill (cut) text in region | emacs | |
| copy region | copy region to kill ring without deleting (kill-ring-save) | emacs | |
| yank | yank (paste) most recent kill from kill ring | emacs |
TODO: use better kill ring and accept that UX is different (update debug settings)
| key | name | description | mode |
|---|---|---|---|
| yank pop | open kill-ring history | emacs | |
| yank next | go to next item in kill-ring history | emacs | |
| yank prev | go to next item in kill-ring history | emacs | |
| kill line | kill from cursor to end of line, or kill newline if at end | emacs | |
| kill whole line | kill entire line including newline | emacs | |
| delete char | delete character forward without adding to kill ring | emacs | |
| kill word →/← | kill word forward / backward | emacs | |
| kill sentence | kill from point to end of sentence | emacs | |
| zap to char | kill text from point up to and including target character | emacs | |
| delete blank lines | delete excess blank lines around point | emacs | |
| delete spaces | delete all spaces and tabs around point | emacs | |
| open line | insert newline after cursor without moving point | emacs |
Transposition
Transposition commands swap adjacent characters, words, or lines.
| key | name | description | mode |
|---|---|---|---|
| transpose chars | transpose two characters before and after cursor | emacs | |
| transpose words | transpose two words | emacs | |
| transpose lines | transpose current line with line above | emacs |
Case Transformations
Modify the case of words starting from point.
| key | name | description | mode |
|---|---|---|---|
| upcase word | convert word to UPPERCASE from point to end of word | emacs | |
| downcase word | convert word to lowercase from point to end of word | emacs | |
| capitalize word | capitalize next word (Title Case) from point to end of word | emacs |
Indentation & Formatting
Indentation and code formatting commands.
| key | name | description | mode |
|---|---|---|---|
| indent | indent current line or selected region according to mode | emacs | |
| newline & indent | insert newline and auto-indent next line | emacs | |
| indent region | re-indent region or format selection (indent-region) | emacs | |
| fill paragraph | reflow and format current paragraph or comment (fill-paragraph) | emacs | |
| comment region | toggle comment for selected lines or current line | emacs |
Undo & Redo
Standard Emacs undo commands (ctrl+/, ctrl+_, ctrl+x u) and redo (val.meta+_).
| key | name | description | mode |
|---|---|---|---|
| undo / redo | undo / redo previous edit | emacs |
Incremental Search & Replace (I-Search)
Incremental search (ctrl+s forward, ctrl+r backward) and interactive query replace (val.meta+shift+5).
| key | name | description | mode |
|---|---|---|---|
| isearch forward/backward | incremental search forward/backward | emacs | |
| query replace | interactively search and replace text (query-replace) | emacs | |
| regex replace | search and replace using regular expressions (query-replace-regexp) | emacs | |
| occur | search pattern across workspace / project files | emacs |
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.
| key | name | description | mode |
|---|---|---|---|
| universal argument | Universal argument prefix (default 4x count multiplier) | emacs | |
| digit 0-9 | Add digit 0-9 to prefix argument count | emacs |
Buffers, Files & Windows
Emacs commands for finding files, saving buffers, switching buffers, and managing multi-window / split layout configurations.
| key | name | description | mode |
|---|---|---|---|
| find file | Open file by path or name (find-file) | emacs | |
| save buffer | Save current file (save-buffer) | emacs | |
| write file | Save current file under a new name (write-file) | emacs | |
| save all | Save all open modified buffers (save-some-buffers) | emacs | |
| switch buffer | Switch active editor to another buffer (switch-to-buffer) | emacs | |
| list buffers | List all open editors and buffers | emacs | |
| kill buffer | Close active editor buffer (kill-buffer) | emacs | |
| dired | Open file explorer / directory manager (dired) | emacs | |
| prev/next buffer | Switch to previous/next editor buffer | emacs | |
| delete window | Close active editor split group (delete-window) | emacs | |
| single window | Close all other editor split groups (delete-other-windows) | emacs | |
| split below | Split editor horizontally below (split-window-below) | emacs | |
| split right | Split editor vertically to the right (split-window-right) | emacs | |
| other window | Navigate cursor to other editor window group (other-window) | emacs | |
| balance windows | Make all editor windows equal width and height | emacs | |
| find file other | Open file in adjacent split group | emacs | |
| kill buffer & window | Close buffer and split window group | emacs | |
| close window | Exit editor window (save-buffers-kill-terminal) | emacs | |
| zen mode | Toggle Zen full-screen distraction-free mode | emacs |
Code Navigation & LSP
Tag jumping and code intelligence commands.
| key | name | description | mode |
|---|---|---|---|
| find definition | Jump to definition of symbol at point (xref-find-definitions) | emacs | |
| pop tag mark | Navigate back to previous jump location (xref-go-back) | emacs | |
| tag forward | Navigate forward to next jump location (xref-go-forward) | emacs | |
| find references | Find all references to symbol at point (xref-find-references) | emacs | |
| complete symbol | Trigger autocomplete suggestions | emacs | |
| hover info | Show documentation / type signature for symbol under point | emacs | |
| rename symbol | Refactor and rename symbol across project | emacs |
Multi-Cursor Selection
Quickly add multiple cursors matching the selected word or find match.
| key | name | description | mode |
|---|---|---|---|
| mark next match | Add cursor at next matching occurrence | emacs | |
| mark prev match | Add cursor at previous matching occurrence | emacs | |
| mark all matches | Add cursors to all matching occurrences (mc/mark-all-like-this) | emacs |
Version Control
Basic version control commands (VC / Git).
| key | name | description | mode |
|---|---|---|---|
| vc status | Open source control / git panel (vc-dir) | emacs | |
| vc diff | Show diff / file changes (vc-diff) | emacs | |
| vc annotate | Show file blame / annotations (vc-annotate) | emacs | |
| vc log | Show commit history log (vc-print-log) | emacs |
Commands & Shell Execution
Execute extended commands by name and launch terminal / shell commands.
| key | name | description | mode |
|---|---|---|---|
| execute command | Open command palette (execute-extended-command) | emacs | |
| shell command | Toggle integrated terminal (shell-command) | emacs |
Keyboard Macros
Record and replay sequences of key commands.
| key | name | description | mode |
|---|---|---|---|
| macro record / call | Start, stop, and replay recorded keyboard macro; nested macros are not supported | emacs |
