My current terminal setup uses iTerm2 and Zsh. Considering the amount of time I spend on the terminal, I wanted to quickly navigate my current input using a combination of modifier and arrow keys.

While iTerm2 allows you to quickly navigate to the front or back of the current input using ⌘ + ← or ⌘ + →, there's no default configuration to move by word.
The requirement was to the map the following keys:

  • ⌥ + ← moves backward by one word
  • ⌥ + → moves forward by one word

The easiest way I've found to achieve this is using Zsh bindkeys. Add the following commmands to your .zshrc to enable this functionality.

bindkey -e
bindkey '\e\e[C' forward-word
bindkey '\e\e[D' backward-word

Moving across your input by one character at a time can be frustrating. Hopefully this makes your terminal experience better!

PS: If you're still using on macOS - Why?