Some may argue that navigating with VIM keyboard shortcuts is not a workaround, but for me it is accurate and very inconvenient and very inefficient. Especially when you need to switch between insert and normal modes to go to the next word.
That's why I came up with a solution based on this answer on SuperUser. The idea is to map the input provided by Terminal.app directly to VIM. The answer to SU shows what to put in your vimrc file for the Home / End keys to work as expected.
My modified version below includes navigation on the words Option+arrow (or Alt+arrow ). I tried to simulate the behavior of a terminal moving as close as possible. Therefore, pressing Option+Right ( Alt+Right ) will move the carriage to the next character after the word (as opposed to the last character of the word, which is VIMs w native bahavior).
let tp=$TERM_PROGRAM if tp == 'Apple_Terminal' :" map Mac OS X Terminal.app " map Home/End: :map <ESC>[H <Home> :map <ESC>[F <End> " small 'o' letter in <Co> means no exit from the insert mode :imap <ESC>[H <Co><Home> :imap <ESC>[F <Co><End> :cmap <ESC>[H <Home> :cmap <ESC>[F <End> " map Option+Left/Option+Right: " for this to work you must have the bindings in Settings > Keyboard set " as follows: " 'option cursor left' to '\033b' " 'option cursor right' to '\033f' :map <ESC>f el :imap <ESC>b <Co>b :imap <ESC>f <Co>el :cmap <ESC>f el endif
As a small but significant bonus, you get start / end navigation without leaving insert mode. Tested on 10.8.5 .
Maciej sz
source share