57 Keyboard mappings
Christian Duerr edited this page 2024-08-10 09:53:49 +00:00

Table of Contents

Syntax documentation

While this includes some helpful examples and tips for changing keyboard mappings in Alacritty, the full syntax is documented in the configuration manpage.

How to create a mapping

  1. Follow the installation guide to set up alacritty
  2. Run alacritty using alacritty --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 unicode (\uNNNN) escapes:

  # Insert the `[` character
  - { key = "LBracket", mods = "Alt", chars = "[" }
  # Send the Ctrl+C control using its unicode value
  - { key = "T", mods = "Control|Shift", chars = "\u0003" }

The virtual_keycode is None

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 = "[" }