User guide / Custom key bindings

Configured macros

Development reference · View source

Macros replay keys through the live keymap, starting in the current mode and pane. Define a name under keys.macros, then bind it with { macro: name }:

keys:
  macros:
    greeting:
      keys: "ihello<Esc>"
      description: Insert a greeting
    next-word: "w"
  bind:
    normal:
      F6: { macro: greeting }
      F7: { macro: next-word }
    insert:
      Ctrl-j: { macro-keys: "<Esc>o" }

{ macro: name } always refers to a defined name; an unknown name is an error. Use { macro-keys: "keys" } for an inline recording. Macro bindings work in all modes and buffer types that execute programs, including terminal Insert, where ordinary replayed keys reach the child process. UI/list owners still take one action in 0.5. A macro cannot be a program step, though a program may end with the existing macro-replay action to replay a recorded register.

Plain characters are keys. Angle brackets name special keys: <Esc>, <Enter>, <Space>, <lt> for <, and <gt> for >. Modifier forms accept short C-, A-, S-, D- or the ordinary Ctrl-, Alt-, Shift-, Super- spellings, for example <C-w> and <Shift-Left>. Write shifted characters literally, rather than <S-a>. Control characters must use named key spellings.

A file macros.d/greeting.yaml beside the configuration defines greeting:

keys: "ihello<Esc>"
description: Insert a greeting

Definitions may be repeated only when their parsed keys and descriptions are identical. A conflict rejects that name and its referencing bindings, with both sources in the diagnostics. Other valid names remain available. Configuration reload rereads these files. Names use 1–128 ASCII letters, digits, dots, hyphens or underscores and cannot begin with a dot. Limits are 256 named macros, 10,000 keys per macro, 1,024 UTF-8 bytes per control-free description, and 256 files of at most 1 MiB each in macros.d.

Counts repeat a macro, and the invoking register prefix does not leak into its keys or the next binding. Replay shares recorded macros’ recursion, nesting, work and cancellation limits. :keymap-export includes every effective named macro under keys.macros, plus named and inline macro bindings. Its identical definitions can be loaded beside the same macros.d directory.

Save the last completed recording with :macro-save <name>, or choose a recorded register with :macro-save <name> @<register>. Spell the space register as @<Space> and a less-than sign as @<lt>. The command writes macros.d/<name>.yaml beside the loaded configuration (or the default configuration when none is loaded), and refuses to overwrite an existing file. Run :config-reload afterward to make the saved definition available. Saving does not add a binding; assign one with { macro: name }.

Only recordings represented exactly by compact key notation can be saved. Mouse events, literal text/paste events, empty recordings, unfinished recordings and keys that cannot round-trip are refused with a reason.

Copy a configured definition with :copy-macro <name>. Unknown names are errors. Copy a recording with :copy-macro @<register> [name], or use :copy-macro without arguments for the last completed recording. The clipboard receives a complete keys.macros YAML entry, preserving keys and description. Recorded entries default to macro-<register>; registers unsuitable for a portable name use macro-u<hex-codepoint> (for example macro-u0040 for the default @ register). An explicit name overrides this default.

Space m l and :help macros open the same list of recorded and configured macros. Each entry shows compact keys, description and source; unrepresentable recordings show the refusal reason. Enter replays the selected macro. The list’s actions menu offers YAML copy, and recorded entries also offer save with an editable name in the command palette. Contextual help continues to show macro bindings in its normal key table.