Skip to main content

Module keymap_cancel

Module keymap_cancel 

Source
Expand description

CG.1 — the foreground-cancel binding (<C-g>).

Design: docs/dev/architecture/cancellation.md; sequencing: docs/dev/operations/slice-plans/cancellation.md.

§The chord

<C-g> — emacs keyboard-quit. Registered at KeymapLayer::Builtin, so it works unconditionally rather than depending on :set emacs-keys.

It is the only apt chord that is actually free. <C-c> — vim’s own interrupt, and the obvious first choice — cannot be used: it is a mode prefix here (<C-c>g / <C-c>f magit dispatch, <C-c><C-c> / <C-c><C-k> commit-rebase-notes), and KeymapTrie::lookup returns Bound at a terminal node regardless of its children, so a depth-1 binding makes every one of those chords unreachable. Of the remaining free CTRL chords (a c g j k m x z): c and x are prefixes, j / m are the literal LF / CR terminals send for Enter, z is the suspend convention, a is vim’s increment and k is Insert’s kill-to-end-of-line.

§Modes covered

Normal, Insert, Replace, and the three readline surfaces — Command, Search, Prompt. The minibuffers resolve keys in their own contexts, not Insert’s (keymap-architecture.md §5.7), so each needs its own entry: while they borrowed the Insert table this set named only the first three, and <C-g> went dead on a stuck : line the day they stopped borrowing it.

Not Visual or Select. SN.3d owns <C-g> there as the Visual↔Select toggle — vim-canonical, and the only path between the two modes that preserves the selection (select-mode.md §4). Those arms are hardcoded ahead of the trie lookup in dispatch_visual / native_select_action, so they would win anyway; leaving the modes out of this set keeps the intent explicit rather than accidental.

The cost is that Visual and Select have no cancel chord: from there it is <Esc> then <C-g>. Accepted deliberately — Visual is a transient state a user is rarely parked in while waiting on a scan, and the alternative was relocating a vim-canonical chord.

§Why not <Esc>

An earlier revision of this slice folded cancellation into <Esc>, which is universal and never a prefix. It was reverted: vim users press <Esc> reflexively and constantly, so a long-running search would die to a habitual double-tap that carried no intent to cancel. Cancellation needs a key the user only presses on purpose.

Constants§

CANCEL_MODES
Every mode <C-g> resolves to action:cancel in. See the module docs for why Visual / Select are absent and why Command / Search / Prompt each need an entry of their own.

Functions§

register_cancel_bindings
Register <C-g> → action:cancel under KeymapLayer::Builtin for every mode in CANCEL_MODES.