Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refo/1e41f210802738e18267914c7379052c to your computer and use it in GitHub Desktop.
Save refo/1e41f210802738e18267914c7379052c to your computer and use it in GitHub Desktop.
iTerm2 navigate between words using option and horizontal arrow keys

Determine bound keys for your terminal emulator

Determine the sequence for one-word backward navigation

bindkey -L | grep backward-word

example output

bindkey "^[B" backward-word
bindkey "^[[1;5D" backward-word
bindkey "^[b" backward-word

Determine the sequence for one-word forward navigation

bindkey -L | grep forward-word

example output

bindkey "^[F" forward-word
bindkey "^[[1;5C" forward-word
bindkey "^[f" forward-word

Which key sequences to use

According to bindkey output, we can pick and choose any of the sequences. ^[ means escape. So decided to use esc + b and esc + f for backward and forward navigation respectivly.

iTerm2 profile config

Open Keys preferences tab. Preferences > Profile > [Selected profile] > Keys

Scroll through Key Mappings to find shortcut you want to modify or add a new one.

I modified the mappings for ⌥ ← and ⌥ → by double clicking and setting the following options:

Keyboard Shortcut : ⌥ ←

Action : Send escape sequence
Esc+   : b
Keyboard Shortcut : ⌥ →

Action : Send escape sequence
Esc+   : b

That's all to be able to use option + left and right to navigate between words on iTerm2 terminal emulator.


Thanks to Filip Danić posting detailed information on the subject.

Original blogpost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment