How to get Cmd-left/right working with iTerm2 and Vim (without requiring .vimrc changes)?

To mimic OS X's behavior of sending Cmd-left/right to the beginning/end of a line, I add the following mappings in iTerm2:

  • Cmd-left to escape-sequence [1~
  • Cmd-right to escape-sequence [4~

To mimic OS X's behavior of sending Option-left/right to the previous/next word, I add the following mappings in iTerm2:

  • Option-left to escape-sequence [1;5D
  • Option-right to escape-sequence [1;5C

Special thanks to this blog post for tracking down what I was missing with the cmd-left/right mappings


FWIW, dolan's answer didn't work for me on iTerm 2 1.0.0.20120203 on Mac OS X 10.7.3. His solution only inserted ~ and 5D/5C into my terminal when I pressed the shortcut keys.

Instead, I used the following solutions:

  • Cmd-left/right: iTerm 2: How to set keyboard shortcuts to jump to beginning/end of line?

  • Option-left/right as well as option-delete: http://hackaddict.blogspot.co.at/2007/07/skip-to-next-or-previous-word-in-iterm.html

YMMV, not sure why one set of solutions would work and not the other


I'm using iTerm2 3.4.2 and there's actually a preset that you can select for your profile that enables this. Profile Key Mappings Natural Text Editing Preset