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

余生长醉 提交于 2019-11-28 18:53:26

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

Ilias Karim

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:

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

I don't have MacOS, so I cannot exactly know your situation, but I recognize the problem from other OSes.

Basically, it would mean that the terminal sends keycodes that aren't understood by vim. I fixed it in the past by doing

 TERM=something
 export TERM

before invoking vim

E.g. in order to get all keys and syntax highlighting working on AIX 5.3 across Putty/screen, I needed to use

 TERM=iris-ansi vim

There is a list of builtin terminal types if you pass a bad TERM

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!