I really wanted to be able to use Option + Left or Option + Right to navigate through words in terminal input. Option + Delete to delete a word is also really handy.
The Terminal App has this feature of using the Option key as a "Meta" key. This unlocks all of those great shortcuts ! This article highlights the shortcuts that are unlocked like this : https://www.shell-tips.com/mac/meta-key/
However this breaks some useful basic shortcuts, like all those used to write unicode characters. The pipe character for instance, printed by Command + Option + L cannot be used anymore when this option is enabled.
Luckily for me, it is possible to configure some of these bindings manually in Settings > Profiles > Keyboard. All I needed to do was add a couple new key bindings :
Shortcut | Keys for typing the escape sequence | Escape sequence | Effect |
---|---|---|---|
Option + Left | Esc + b | \033b | Move forward one word (vs per character) |
Option + Right | Esc + f | \033f | Move backward one word (vs per character) |
Option + Delete | Esc + Delete | \033\177 | Delete word backward from cursor |
Fn + Left | Esc + O + H | \033OH | Move to start of the line |
Fn + Right | Esc + O + F | \033OF | Move to end of the line |