User guide / Custom key bindings

Named modes and buffer types

Development reference · View source

A binding lives in keys.bind.<mode>. Lookup starts in the active named mode, then follows its single inherits parent until a binding is found. There is no second global or buffer-type lookup. A binding table implicitly declares its mode, even when the table is empty. The Runyte preset exposes three stable shared-mode names:

  • common: the parent shared by editing and specialized buffer-type modes, including Insert and Replace. An action here must be valid in every inheriting mode.
  • modal-keys: shared by the preset’s Normal/Select families and modal buffer types. Use it for former global Normal bindings; it does not supply text-entry keys.
  • insert-keys: shared by the preset’s Insert/Replace families, including terminal input modes. Actions must be valid in all those destinations.

They are ordinary inherited modes: a child may override or remove a key, and a custom mode only receives their bindings if its inheritance reaches them. For example:

keys:
  bind:
    common:
      Ctrl-s: save
    modal-keys:
      F6: yank
    insert-keys:
      Alt-Left: move-left

Use a narrower named mode when an action is not valid everywhere that inherits the shared table. For example, insert-newline belongs in a text Insert mode, not common or the terminal’s input table.

modes:
  writing:
    inherits: normal
    unbound-keys: report
buffer-types:
  markdown:
    normal: writing
    select: markdown-select
    insert: insert
    replace: replace
keys:
  bind:
    common:
      Ctrl-s: save
    writing:
      j: move-up
      k: null
    list:
      F9: list-next
      Ctrl-n: null
    session-manager:
      F8: list-previous

An exact null suppresses that key throughout the inherited chain. It does not reveal the parent binding or remove longer sequences beginning with the same key. A child binding replaces the inherited key and its longer sequences. Only one parent is supported; cycles, unknown parents and unknown role targets are rejected. The effective graph has at most 256 modes, names have at most 64 ASCII letters, digits, hyphens or underscores, and inheritance has at most 64 levels.

buffer-types entries map normal, select, insert and replace roles to named modes. The normal role supplies the starting mode. The scalar shorthand markdown: writing supplies that normal role and uses shared select, insert and replace modes when they exist. An explicit mapping supplies exactly the listed roles. Entering an omitted role is unavailable and stops the binding. Internal mode-entry steps resolve role names through this mapping; other declared names enter that mode directly. Roles still determine action admission and temporary restoration; input, overwrite, motion and selection behavior read the named mode’s properties. Terminal activation preserves live input or review.

unbound-keys accepts report, pass-to-buffer and overwrite. It defaults to report; the built-in Insert and Replace modes declare the corresponding text-input policies. The motions property inherits; unbound-keys and display-name belong to the mode itself. Mode declarations merge property by property with the preset, while a supplied buffer-type role mapping replaces that type’s entire mapping. Reload retains a submode by name only while its editing role stays the same; otherwise it returns to the current buffer type’s mapped role. If focus, reload or restoration carries a role the destination omits, it falls back to Normal. The UI-owned list and session-manager tables cannot be editing-role targets or parents of editor modes. A shared table may contain an action available in only some inheriting roles; execution still checks availability in the active role before that action runs.

The preset’s normal inherits shared modal keys, and select inherits normal. Markdown inherits normal; other specialized buffer types have their own named modes. For example, keys.bind.markdown changes Markdown normal and its inheriting Select mode, while keys.bind.markdown-select changes Select alone. Terminal input uses keys.bind.terminal-insert:

keys:
  bind:
    terminal-insert:
      F6: [fit-selection-for-normal-mode, {action: mode-enter, arg: normal}]
      Ctrl-4: null
      'Ctrl-\': null
      'F7 h': pane-focus-left

Ordinary terminal keys still reach the child. An assigned action claims its first key and following sequence. A null removes the exact binding; surviving longer bindings retain their prefix. Terminal input uses its own mode bindings. Terminal review and specialized buffer types still apply their runtime action availability checks.

Result lists use keys.bind.list; session-manager overrides use keys.bind.session-manager. List bindings have one key and support list-next, list-previous, list-page-down, list-page-up, list-first, list-last, list-toggle-preview, list-clear-filter, list-close-target, list-close, list-accept, list-backspace and list-open-actions. Exact modifier spellings are independent. Numbered session choices and nested action menus retain their own input ownership. keys.ui.list-close configures close confirmations.

Bindings accept action names, action lists, argument mappings, mode entry, and conditional branches. Prefixes have at most eight keys. Prompt, menu, overlay and native controls remain under keys.ui; they are not named editor modes.