2020-05-22 18:05:59 +03:00
## Configuring Key Assignments
2022-04-04 19:28:26 +03:00
The default key table assignments can be overridden or extended using the
`keys` section in your `~/.wezterm.lua` config file. For example, you can
disable a default assignment like this:
2019-12-30 07:41:08 +03:00
2020-04-07 02:32:16 +03:00
```lua
2023-03-20 04:26:21 +03:00
config.keys = {
-- Turn off the default CMD-m Hide action, allowing CMD-m to
-- be potentially recognized and handled by the tab
{
key = 'm',
mods = 'CMD',
action = wezterm.action.DisableDefaultAssignment,
2022-07-19 17:54:31 +03:00
},
2020-04-07 02:32:16 +03:00
}
2019-12-30 07:41:08 +03:00
```
2021-10-03 19:10:04 +03:00
The `action` value can be one of the [available key
assignments](lua/keyassignment/index.md). Every action has an example that shows
how to use it.
2022-02-18 16:29:02 +03:00
Possible Modifier labels are:
* `SUPER` , `CMD` , `WIN` - these are all equivalent: on macOS the `Command` key,
on Windows the `Windows` key, on Linux this can also be the `Super` or `Hyper`
key. Left and right are equivalent.
2022-08-18 21:09:26 +03:00
* `CTRL` - The control key. Left and right are equivalent.
2022-02-18 16:29:02 +03:00
* `SHIFT` - The shift key. Left and right are equivalent.
* `ALT` , `OPT` , `META` - these are all equivalent: on macOS the `Option` key,
on other systems the `Alt` or `Meta` key. Left and right are equivalent.
2022-04-04 19:28:26 +03:00
* `LEADER` - a special modal modifier state managed by `wezterm` . See [Leader Key ](#leader-key ) for more information.
2022-02-18 16:29:02 +03:00
* `VoidSymbol` - This keycode is emitted in special cases where the original
function of the key has been removed. Such as in Linux and using `setxkbmap` .
`setxkbmap -option caps:none` . The `CapsLock` will no longer function as
before in all applications, instead emitting `VoidSymbol` .
You can combine modifiers using the `|` symbol (eg: `"CMD|CTRL"` ).
2019-12-30 07:41:08 +03:00
The `key` value can be one of the following keycode identifiers. Note that not
all of these are meaningful on all platforms:
`Hyper` , `Super` , `Meta` , `Cancel` , `Backspace` , `Tab` , `Clear` , `Enter` ,
`Shift` , `Escape` , `LeftShift` , `RightShift` , `Control` , `LeftControl` ,
`RightControl` , `Alt` , `LeftAlt` , `RightAlt` , `Menu` , `LeftMenu` , `RightMenu` ,
2021-05-07 17:54:24 +03:00
`Pause` , `CapsLock` , `VoidSymbol` , `PageUp` , `PageDown` , `End` , `Home` , `LeftArrow` ,
2019-12-30 07:41:08 +03:00
`RightArrow` , `UpArrow` , `DownArrow` , `Select` , `Print` , `Execute` ,
`PrintScreen` , `Insert` , `Delete` , `Help` , `LeftWindows` , `RightWindows` ,
`Applications` , `Sleep` , `Numpad0` , `Numpad1` , `Numpad2` , `Numpad3` ,
`Numpad4` , `Numpad5` , `Numpad6` , `Numpad7` , `Numpad8` , `Numpad9` , `Multiply` ,
`Add` , `Separator` , `Subtract` , `Decimal` , `Divide` , `NumLock` , `ScrollLock` ,
`BrowserBack` , `BrowserForward` , `BrowserRefresh` , `BrowserStop` ,
`BrowserSearch` , `BrowserFavorites` , `BrowserHome` , `VolumeMute` ,
`VolumeDown` , `VolumeUp` , `MediaNextTrack` , `MediaPrevTrack` , `MediaStop` ,
`MediaPlayPause` , `ApplicationLeftArrow` , `ApplicationRightArrow` ,
2021-03-09 18:47:27 +03:00
`ApplicationUpArrow` , `ApplicationDownArrow` , `F1` , `F2` , `F3` , `F4` ,
`F5` , `F6` , `F7` , `F8` , `F9` , `F10` , `F11` , `F12` , `F13` , `F14` , `F15` ,
`F16` , `F17` , `F18` , `F19` , `F20` , `F21` , `F22` , `F23` , `F24` .
2019-12-30 07:41:08 +03:00
Alternatively, a single unicode character can be specified to indicate
pressing the corresponding key.
2022-04-04 19:28:26 +03:00
Pay attention to the case of the text that you use and the state of the `SHIFT` modifier, as `key="A"` will match
2022-02-18 16:29:02 +03:00
### Physical vs Mapped Key Assignments
2019-12-30 07:41:08 +03:00
2023-03-21 08:01:24 +03:00
{{since('20220319-142410-0fcdea07')}}
2019-12-30 07:41:08 +03:00
2022-02-18 16:29:02 +03:00
The `key` value can refer either to the physical position of a key on an ANSI
US keyboard or to the post-keyboard-layout-mapped value produced by a key
press.
You can explicitly assign using the physical position by adding a `phys:` prefix
to the value, for example: `key="phys:A"` . This will match key presses for
the key that would be in the position of the `A` key on an ANSI US keyboard.
You can explicitly assign the mapped key by adding a `mapped:` prefix to the
value, for example: `key="mapped:a"` will match a key press where the OS
keyboard layout produces `a` , regardless of its physical position.
If you omit an explicit prefix, wezterm will assume `phys:` and use the
physical position of the specified key.
The default key assignments listed above use `phys:` . In previous releases
there was no physical position support and those assignments were all `mapped:` .
When upgrading from earlier releases, if you had `{key="N", mods="CMD", ..}` in
2022-03-29 17:56:56 +03:00
your config, you will need to change it to either
2022-02-18 16:29:02 +03:00
`{key="N", mods="CMD|SHIFT", ..}` or `{key="mapped:N", mods="CMD", ..}`
in order to continue to respect the `SHIFT` modifier.
2019-12-30 07:41:08 +03:00
2023-03-21 08:01:24 +03:00
{{since('20220408-101518-b908e2dd')}}
2022-04-01 18:07:23 +03:00
A new `key_map_preference` option controls how keys without an explicit `phys:`
or `mapped:` prefix are treated. If `key_map_preference = "Mapped"` (the
default), then `mapped:` is assumed. If `key_map_preference = "Physical"` then
`phys:` is assumed.
The default key assignments will respect `key_map_preference` .
2022-04-04 19:28:26 +03:00
### Raw Key Assignments
In some cases, `wezterm` may not know how to represent a key event in either
its `phys:` or `mapped:` forms. In that case, you may wish to define an
assignment in terms of the underlying operating system key code, using a `raw:`
prefix.
Similar in concept to the `phys:` mapping described above, the `raw:` mapping
is independent of the OS keyboard layout. Raw codes are hardware and windowing system dependent, so there is no portable way to list which key does what.
To discover these values, you can set [debug_key_events =
true](lua/config/debug_key_events.md) and press the keys of
interest.
You can specify a raw key value of 123 by using `key="raw:123"` in your config
rather than one of the other key values.
2020-10-10 19:57:38 +03:00
### Leader Key
2023-03-21 08:01:24 +03:00
{{since('20201031-154415-9614e117')}}
2020-10-10 19:57:38 +03:00
A *leader* key is a a modal modifier key. If leader is specified in the
configuration then pressing that key combination will enable a virtual `LEADER`
modifier.
While `LEADER` is active, only defined key assignments that include
`LEADER` in the `mods` mask will be recognized. Other keypresses
will be swallowed and NOT passed through to the terminal.
`LEADER` stays active until a keypress is registered (whether it
matches a key binding or not), or until it has been active for
the duration specified by `timeout_milliseconds` , at which point
it will automatically cancel itself.
Here's an example configuration using `LEADER` . In this configuration,
pressing `CTRL-A` activates the leader key for up to 1 second (1000
milliseconds). While `LEADER` is active, the `|` key (with no other modifiers)
will trigger the current pane to be split.
```lua
2023-03-20 04:26:21 +03:00
-- timeout_milliseconds defaults to 1000 and can be omitted
config.leader = { key = 'a', mods = 'CTRL', timeout_milliseconds = 1000 }
config.keys = {
{
key = '|',
mods = 'LEADER|SHIFT',
action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
},
-- Send "CTRL-A" to the terminal when pressing CTRL-A, CTRL-A
{
key = 'a',
mods = 'LEADER|CTRL',
action = wezterm.action.SendString '\x01',
2022-07-19 17:54:31 +03:00
},
2020-10-10 19:57:38 +03:00
}
```
2021-05-07 17:59:26 +03:00
### VoidSymbol
2023-03-21 08:01:24 +03:00
{{since('20210814-124438-54e29167')}}
2021-05-07 17:59:26 +03:00
On X11 systems, If you decide to change certain keys on the keyboard to
`VoidSymbol` (like `CapsLock` ), then you can utilize it as a `LEADER` or any
other part of key bindings. The following example now uses `VoidSymbol` and
uses `CapsLock` as a `LEADER` without it affecting the shift / capital state as
long as you have `setxkbmap -option caps:none` configured.
2021-05-07 17:54:24 +03:00
```lua
2023-03-20 04:26:21 +03:00
-- timeout_milliseconds defaults to 1000 and can be omitted
-- for this example use `setxkbmap -option caps:none` in your terminal.
config.leader = { key = 'VoidSymbol', mods = '', timeout_milliseconds = 1000 }
config.keys = {
{
key = '|',
mods = 'LEADER|SHIFT',
action = wezterm.action.SplitHorizontal { domain = 'CurrentPaneDomain' },
},
{
key = '-',
mods = 'LEADER',
action = wezterm.action.SplitVertical { domain = 'CurrentPaneDomain' },
2022-07-19 17:54:31 +03:00
},
2021-05-07 17:54:24 +03:00
}
```
2020-10-10 18:40:14 +03:00
# Available Actions
2019-12-30 07:41:08 +03:00
2020-10-10 18:40:14 +03:00
See the [`KeyAssignment` reference ](lua/keyassignment/index.md ) for information
on available actions.
2019-12-30 07:41:08 +03:00