Add support for custom key macros #322

Closed
opened 2025-10-14 15:45:58 -06:00 by navan · 0 comments
Owner

Originally created by @ulyssa on 3/10/2024

This adds a "macros" field to config.json which allows specifying custom mappings from one set of keys to another. This allows writing something like the following to map jj to <Esc> in Insert mode:

{
    ...,
    "macros": {
        "i": { "jj": "<Esc>" }
    }
}

The following names can be used to refer to the different modes:

  • normal/n for Normal mode
  • insert/i for Insert mode
  • visual/v for Visual mode
  • command/c for Command mode
  • select for Select mode
  • operator-pending for Operator Pending mode

Multiple modes can be specified together using | to put a mapping in all of them. For example, "insert|command" or "i|c" could be used in the above example to map jj in both Insert and Command mode.

I've called this "macros" since they'll behave like macros: a {count} argument will repeat the mapping (<Esc> in the above example), and not provide an argument to it. I have plans for a separate way to specify keybindings in the future using expressions that generate an Action that should help anyone who needs to specify something that takes an optional count or register argument.

*Originally created by @ulyssa on 3/10/2024* This adds a `"macros"` field to `config.json` which allows specifying custom mappings from one set of keys to another. This allows writing something like the following to map `jj` to `<Esc>` in Insert mode: ```json { ..., "macros": { "i": { "jj": "<Esc>" } } } ``` The following names can be used to refer to the different modes: - `normal`/`n` for Normal mode - `insert`/`i` for Insert mode - `visual`/`v` for Visual mode - `command`/`c` for Command mode - `select` for Select mode - `operator-pending` for Operator Pending mode Multiple modes can be specified together using `|` to put a mapping in all of them. For example, `"insert|command"` or `"i|c"` could be used in the above example to map `jj` in both Insert and Command mode. I've called this `"macros"` since they'll behave like macros: a `{count}` argument will repeat the mapping (`<Esc>` in the above example), and not provide an argument to it. I have plans for a separate way to specify keybindings in the future using expressions that generate an `Action` that should help anyone who needs to specify something that takes an optional count or register argument.
navan closed this issue 2025-10-14 15:45:58 -06:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/iamb#322
No description provided.