Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binding option left and right arrows to move by words in zsh command line

Tags:

shell

zsh

zshrc

I'm using iTerm2 on Mac OSX 10.8 with an xterm key binding and zsh.

I'd like zsh to use option left arrow and option right arrow to do the standard Mac bindings of left and right word.

If I hit ctrl-v then option-left and right arrows, where are the two key sequences that print:

^[[1;9D 

^[[1;9C

I tried using binding these sequences using bindkey -v, but with no luck.

like image 694
justingordon Avatar asked Nov 23 '13 21:11

justingordon


1 Answers

You can configure iTerm2 to do this like so:

  • Go to iTerm2 > Preferences > Profiles > Keys
  • If there is already an ⌥ ← or ⌥ → setting, delete it by selecting it and hitting -.
  • Add a new shortcut by hitting the + button.
  • Type + in the Keyboard shortcut box.
  • Select Send Escape Sequence in the Action box.
  • Enter b for Characters to send.
  • Click Ok.

Repeat the above procedure for ⌥ →, this time entering f for the Characters to send.

Taken from this great tutorial which describes the whole process in detail and with pictures:
Use ⌥ ← and ⌥ → to jump forwards / backwards words in iTerm 2, on OS X | Coderwall

like image 74
savanto Avatar answered Oct 04 '22 03:10

savanto