Keyboard mappings
Christian Duerr edited this page Jul 11, 2023
·
56 revisions
While this includes some helpful examples and tips for changing keyboard mappings in Alacritty, the full syntax is documented in the configuration manpage.
- Follow the installation guide to set up
alacritty
- Run
alacritty
usingalacritty --print-events
(use./target/release/osx/Alacritty.app/Contents/MacOS/alacritty
on Mac OS)
At this point, Alacritty should log events pairs like this:
glutin event: WindowEvent { window_id: WindowId(Id(140237741461568)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 33, state: Pressed, virtual_keycode: Some(LBracket), modifiers: ModifiersState { shift: false, ctrl: false, alt: true, logo: false } } } }
glutin event: WindowEvent { window_id: WindowId(Id(140237741461568)), event: ReceivedCharacter('[') }
We're interested in:
- The value between the brackets of
Some
, which is the one to use in the key property of the mapping - The boolean properties in
ModifiersState
, which indicate which modifiers to add in the mods property of the mapping (these can be concatenated using the|
character)
The value for the chars
property of each entry in key_bindings:
can be any text string and supports both hexadecimal (\xNN
) and unicode (\uNNNN
) escapes:
# Insert the `[` character
- { key: LBracket, mods: Alt, chars: "[" }
# Send the Ctrl+C control using its hex value...
- { key: T, mods: Control|Shift, chars: "\x03" }
# ... or using its unicode value
- { key: T, mods: Control|Shift, chars: "\u0003" }
If Alacritty is not able to find the correct keycode for the pressed key, it might be None
. However, it's still possible to map the key yourself by using its scancode.
The scancode is also printed in the output of --print-events
and can be used directly in the key
field of a mapping:
- { key: 33, mods: Alt, chars: "[" }