Victor Cui
Victor Cui

Reputation: 1705

Move cursor word by word in Alacritty

I recently started using Alacritty instead of the default Terminal.app on macOS. When using Terminal, I can jump word by word using Option with left and right arrow keys. In Alacritty this key combination is causing ;3D and ;2D to print to the screen instead of the cursor moving.

Is there a way configure Alacritty to jump word by word using Option and arrow keys?

Upvotes: 33

Views: 9355

Answers (3)

Acaibird
Acaibird

Reputation: 49

This is my configuration, which implements all the shortcuts that require the alt key in a bash environment.

[keyboard]
bindings = [
  { key = "B", mods = "Alt", chars = "\u001BB" },  # Alt + B (Move backward one word)
  { key = "F", mods = "Alt", chars = "\u001BF" },  # Alt + F (Move forward one word)
  { key = "D", mods = "Alt", chars = "\u001BD" },  # Alt + D (Delete the word after the cursor)
  { key = "Backspace", mods = "Alt", chars = "\u001B\u007F" },  # Alt + Backspace (Delete word before cursor)
  { key = "U", mods = "Alt", chars = "\u001BU" },  # Alt + U (Uppercase from cursor to end of word)
  { key = "L", mods = "Alt", chars = "\u001BL" },  # Alt + L (Lowercase from cursor to end of word)
  { key = "C", mods = "Alt", chars = "\u001BC" },  # Alt + C (Capitalize the current word)
  { key = ".", mods = "Alt", chars = "\u001B." },  # Alt + . (Insert the last argument of previous command)
  { key = "Y", mods = "Alt", chars = "\u001BY" },  # Alt + Y (Yank the top of the kill-ring)
  { key = "/", mods = "Alt", chars = "\u001B/" },  # Alt + / (Attempt completion)
  { key = "T", mods = "Alt", chars = "\u001BT" },  # Alt + T (Transpose the words around cursor)
  { key = "R", mods = "Alt", chars = "\u001BR" },  # Alt + R (Recall the last command that matches input)
  { key = "N", mods = "Alt", chars = "\u001BN" },  # Alt + N (Search forward through history)
  { key = "P", mods = "Alt", chars = "\u001BP" },  # Alt + P (Search backward through history)
  { key = "Q", mods = "Alt", chars = "\u001BQ" }   # Alt + Q (Not a standard bash shortcut, customizable)
]

Upvotes: 3

blake
blake

Reputation: 601

Since alacritty 0.13.1, config in yaml format is no longer supported, and the current version of toml doesn't support \x1B. Instead, use \u001B.

Here is an equivalent example c.f. @cfstras's example. The config file should also be called config.toml instead of config.yml now.

[keyboard]
bindings = [
  { key = "Right", mods = "Alt", chars = "\u001BF" },
  { key = "Left",  mods = "Alt", chars = "\u001BB" },
]

Upvotes: 42

cfstras
cfstras

Reputation: 1858

With tmux and zsh, add these to the alacritty config:

key_bindings:
  ...
  - { key: Right, mods: Alt, chars: "\x1BF" }
  - { key: Left,  mods: Alt, chars: "\x1BB" }

Upvotes: 55

Related Questions