2023-03-06 13:27:17 +04:00
# Key remapping
2021-06-17 15:08:05 +04:00
2023-03-06 13:27:17 +04:00
Helix currently supports one-way key remapping through a simple TOML configuration
2021-06-17 15:08:05 +04:00
file. (More powerful solutions such as rebinding via commands will be
2021-10-23 03:54:02 +04:00
available in the future).
2021-06-17 15:08:05 +04:00
2023-03-06 13:27:17 +04:00
To remap keys, create a `config.toml` file in your `helix` configuration
directory (default `~/.config/helix` on Linux systems) with a structure like
2021-06-17 15:08:05 +04:00
this:
```toml
# At most one section each of 'keys.normal', 'keys.insert' and 'keys.select'
[keys.normal]
2023-03-06 13:27:17 +04:00
C-s = ":w" # Maps Ctrl-s to the typable command :w which is an alias for :write (save file)
C-o = ":open ~/.config/helix/config.toml" # Maps Ctrl-o to opening of the helix config file
2021-06-17 15:08:05 +04:00
a = "move_char_left" # Maps the 'a' key to the move_char_left command
w = "move_line_up" # Maps the 'w' key move_line_up
book: Refer to keys by key names, not representations
This is an attempt to clean up the inconsistent way that keys are
written in various places. These rules require the fewest changes to the
existing text.
Use the "Key name", as defined in remapping.md, which uses
"Some-Modifiers-PascalCaseKey". The "Representation", which uses
"S-M-lowercasekey", is only used for configuration entries.
For key combinations which do not present a popup, just present the keys
one after the other, with no intervening space, like `]p`.
For key combinations which present a popup, separate them with ` + `,
like `Space + f`.
The Ctrl modifier is called Ctrl, not Control.
2022-10-10 22:32:05 +04:00
"C-S-esc" = "extend_line" # Maps Ctrl-Shift-Escape to extend_line
2021-08-18 04:53:50 +04:00
g = { a = "code_action" } # Maps `ga` to show possible code actions
2021-11-11 08:44:50 +04:00
"ret" = ["open_below", "normal_mode"] # Maps the enter key to open_below then re-enter normal mode
2021-06-17 15:08:05 +04:00
[keys.insert]
2023-03-06 13:27:17 +04:00
"A-x" = "normal_mode" # Maps Alt-X to enter normal mode
2021-08-18 04:53:50 +04:00
j = { k = "normal_mode" } # Maps `jk` to exit insert mode
2021-06-17 15:08:05 +04:00
```
2023-01-17 12:48:43 +04:00
## Minor modes
Minor modes are accessed by pressing a key (usually from normal mode), giving access to dedicated bindings. Bindings
can be modified or added by nesting definitions.
```toml
[keys.insert.j]
k = "normal_mode" # Maps `jk` to exit insert mode
[keys.normal.g]
a = "code_action" # Maps `ga` to show possible code actions
# invert `j` and `k` in view mode
[keys.normal.z]
j = "scroll_up"
k = "scroll_down"
# create a new minor mode bound to `+`
[keys.normal."+"]
m = ":run-shell-command make"
c = ":run-shell-command cargo build"
t = ":run-shell-command cargo test"
```
## Special keys and modifiers
2023-01-16 14:13:03 +04:00
book: Refer to keys by key names, not representations
This is an attempt to clean up the inconsistent way that keys are
written in various places. These rules require the fewest changes to the
existing text.
Use the "Key name", as defined in remapping.md, which uses
"Some-Modifiers-PascalCaseKey". The "Representation", which uses
"S-M-lowercasekey", is only used for configuration entries.
For key combinations which do not present a popup, just present the keys
one after the other, with no intervening space, like `]p`.
For key combinations which present a popup, separate them with ` + `,
like `Space + f`.
The Ctrl modifier is called Ctrl, not Control.
2022-10-10 22:32:05 +04:00
Ctrl, Shift and Alt modifiers are encoded respectively with the prefixes
2021-06-17 15:08:05 +04:00
`C-` , `S-` and `A-` . Special keys are encoded as follows:
2021-06-20 06:47:22 +04:00
| Key name | Representation |
| --- | --- |
| Backspace | `"backspace"` |
| Space | `"space"` |
| Return/Enter | `"ret"` |
| \- | `"minus"` |
| Left | `"left"` |
| Right | `"right"` |
| Up | `"up"` |
2021-11-08 19:14:03 +04:00
| Down | `"down"` |
2021-06-20 06:47:22 +04:00
| Home | `"home"` |
| End | `"end"` |
2021-12-06 07:24:25 +04:00
| Page Up | `"pageup"` |
| Page Down | `"pagedown"` |
2021-06-20 06:47:22 +04:00
| Tab | `"tab"` |
| Delete | `"del"` |
| Insert | `"ins"` |
| Null | `"null"` |
| Escape | `"esc"` |
2021-06-17 15:08:05 +04:00
2021-09-13 12:48:12 +04:00
Keys can be disabled by binding them to the `no_op` command.
2023-03-06 13:27:17 +04:00
A list of commands is available in the [Keymap ](https://docs.helix-editor.com/keymap.html ) documentation
and in the source code at [`helix-term/src/commands.rs` ](https://github.com/helix-editor/helix/blob/master/helix-term/src/commands.rs ) at the invocation of `static_commands!` macro and the `TypableCommandList` .