Last Updated: August 24, 2021
·
58.22K
· teamon

zsh + iTerm2 OSX shortcuts

We all love OSX built-in shortcuts
⌥ + ← or → - move one word backward/forward
⌘ + ← or → - move to beginning/end of line

In zsh you can use ctrl + a/e to move to beginning/end of line and esc + W/B to move one word backward/forward, but that's not very handy.

Here is a solution to map ⌥ + ← / → and ⌘ + ← / → to work in iTerm2 as expected

Put this in your .zshrc

bindkey "[D" backward-word
bindkey "[C" forward-word
bindkey "^[a" beginning-of-line
bindkey "^[e" end-of-line

Then open iTerm2 preferences and set

iterm2 preferences

You have to choose "Send escape sequence" action and put there only "a" or "e".

PROFIT!

1 Response
Add your response

thank you very much for this. The goto beginning of line and end of line works just perfect with this however to move from words I have to put like this:

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

over 1 year ago ·