Debian Codegraph @

book/src/remapping.md

raw symbols SCIP
1 ## Key remapping
2
3 Helix currently supports one-way key remapping through a simple TOML configuration
4 file. (More powerful solutions such as rebinding via commands will be
5 available in the future).
6
7 There are three kinds of commands that can be used in keymaps:
8
9 * Static commands: commands like `move_char_right` which are usually bound to
10 keys and used for movement and editing. A list of static commands is
11 available in the [Keymap](./keymap.md) documentation and in the source code
12 in [`helix-term/src/commands.rs`](https://github.com/helix-editor/helix/blob/master/helix-term/src/commands.rs)
13 at the invocation of `static_commands!` macro.
14 * Typable commands: commands that can be executed from command mode (`:`), for
15 example `:write!`. See the [Commands](./commands.md) documentation for a
16 list of available typeable commands or the `TypableCommandList` declaration in
17 the source code at [`helix-term/src/commands/typed.rs`](https://github.com/helix-editor/helix/blob/master/helix-term/src/commands/typed.rs).
18 * Macros: sequences of keys that are executed in order. These keybindings
19 start with `@` and then list any number of keys to be executed. For example
20 `@miw` can be used to select the surrounding word. For now, macro keybindings
21 are not allowed in keybinding sequences due to limitations in the way that
22 command sequences are executed. Modifier keys (e.g. Alt+o) can be used
23 like `"<A-o>"`, e.g. `"@miw<A-o>"`
24
25 To remap keys, create a `config.toml` file in your `helix` configuration
26 directory (default `~/.config/helix` on Linux systems) with a structure like
27 this:
28
29 > 💡 To set a modifier + key as a keymap, type `A-X = ...` or `C-X = ...` for Alt + X or Ctrl + X. Combine with Shift using a dash, e.g. `C-S-esc`.
30 > Within macros, wrap them in `<>`, e.g. `<A-X>` and `<C-X>` to distinguish from the `A` or `C` keys.
31
32 ```toml
33 # At most one section each of 'keys.normal', 'keys.insert' and 'keys.select'
34 [keys.normal]
35 C-s = ":w" # Maps Ctrl-s to the typable command :w which is an alias for :write (save file)
36 C-o = ":open ~/.config/helix/config.toml" # Maps Ctrl-o to opening of the helix config file
37 a = "move_char_left" # Maps the 'a' key to the move_char_left command
38 w = "move_line_up" # Maps the 'w' key move_line_up
39 "C-S-esc" = "extend_line" # Maps Ctrl-Shift-Escape to extend_line
40 g = { a = "code_action" } # Maps `ga` to show possible code actions
41 "ret" = ["open_below", "normal_mode"] # Maps the enter key to open_below then re-enter normal mode
42 "A-x" = "@x<A-d>" # Maps Alt-x to a macro selecting the whole line and deleting it without yanking it
43
44 [keys.insert]
45 "A-x" = "normal_mode" # Maps Alt-X to enter normal mode
46 j = { k = "normal_mode" } # Maps `jk` to exit insert mode
47 ```
48
49 ## Minor modes
50
51 Minor modes are accessed by pressing a key (usually from normal mode), giving access to dedicated bindings. Bindings
52 can be modified or added by nesting definitions.
53
54 ```toml
55 [keys.insert.j]
56 k = "normal_mode" # Maps `jk` to exit insert mode
57
58 [keys.normal.g]
59 a = "code_action" # Maps `ga` to show possible code actions
60
61 # invert `j` and `k` in view mode
62 [keys.normal.z]
63 j = "scroll_up"
64 k = "scroll_down"
65
66 # create a new minor mode bound to `+`
67 [keys.normal."+"]
68 m = ":run-shell-command make"
69 c = ":run-shell-command cargo build"
70 t = ":run-shell-command cargo test"
71 ```
72
73 ## Special keys and modifiers
74
75 Ctrl, Shift and Alt modifiers are encoded respectively with the prefixes `C-`, `S-` and `A-`.
76
77 The [Super key](https://en.wikipedia.org/wiki/Super_key_(keyboard_button)) - the Windows/Linux
78 key or the Command key on Mac keyboards - is also supported when using a terminal emulator that
79 supports the [enhanced keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol).
80 The super key is encoded with prefixes `Meta-`, `Cmd-` or `Win-`. These are all synonyms for the
81 super modifier - binding a key with a `Win-` modifier will mean it can be used with the
82 Windows/Linux key or the Command key.
83
84 ```toml
85 [keys.normal]
86 C-s = ":write" # Ctrl and 's' to write
87 Cmd-s = ":write" # Cmd or Win or Meta and 's' to write
88 ```
89
90 Special keys are encoded as follows:
91
92 | Key name | Representation |
93 | --- | --- |
94 | Backspace | `"backspace"` |
95 | Space | `"space"` |
96 | Return/Enter | `"ret"` |
97 | Left | `"left"` |
98 | Right | `"right"` |
99 | Up | `"up"` |
100 | Down | `"down"` |
101 | Home | `"home"` |
102 | End | `"end"` |
103 | Page Up | `"pageup"` |
104 | Page Down | `"pagedown"` |
105 | Tab | `"tab"` |
106 | Delete | `"del"` |
107 | Insert | `"ins"` |
108 | Null | `"null"` |
109 | Escape | `"esc"` |
110 | Less Than (<) | `"lt"` |
111 | Greater Than (>) | `"gt"` |
112
113 Keys can be disabled by binding them to the `no_op` command.
114
115 All other keys such as `?`, `!`, `-` etc. can be used literally:
116
117 ```toml
118 [keys.normal]
119 "?" = ":write"
120 "!" = ":write"
121 "-" = ":write"
122 ```
123
124 Note: `-` can't be used when combined with a modifier, for example `Alt` + `-` should be written as `A-minus`. `A--` is not accepted.