我最近开始使用 Alacritty,而不是 macOS 上的默认 Terminal.app。使用终端时,我可以使用 Option 和左右箭头键逐字跳转。在 Alacritty 中,此组合键导致
;3D
和 ;2D
打印到屏幕上,而不是光标移动。
有没有办法配置 Alacritty 使用 Option 和箭头键逐字跳转?
使用 tmux 和 zsh,将它们添加到 alacritty 配置中:
key_bindings:
...
- { key: Right, mods: Alt, chars: "\x1BF" }
- { key: Left, mods: Alt, chars: "\x1BB" }
自 alacritty 0.13.1 开始,不再支持 yaml 格式的配置,当前版本的 toml 也不支持
\x1B
。相反,请使用 \u001B
。
这是一个等效的例子c.f. @cfstras 的例子。配置文件现在也应该被称为
config.toml
而不是 config.yml
。
[keyboard]
bindings = [
{ key = "Right", mods = "Alt", chars = "\u001BF" },
{ key = "Left", mods = "Alt", chars = "\u001BB" },
]
这是我的配置,它实现了 bash 环境中需要 alt 键的所有快捷键。
[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)
]