有些人可能會爭辯說,動搖VIM native keyboard shortcuts不是一種解決方法,但對我來說,它肯定是非常不方便和非常低效。尤其是您需要在insert
模式和normal
模式之間切換的部分,以便移至下一個單詞。
這就是爲什麼我想出了一個基於SuperUser上的this answer的解決方案。這個想法是直接在VIM中映射由Terminal.app
提供的輸入。 SU上的答案顯示如何將vimrc
文件放入Home/End鍵以按預期工作。
我在下面的調整版本包括Option+arrow
(或Alt+arrow
)導航的話。我試圖模仿終端移動的行爲,儘可能接近我的能力。因此,按Option+Right
(Alt+Right
)會將該插入符號移動到該單詞後面的下一個字符(而不是該單詞的最後一個字符,即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 <C-o> means no exit from the insert mode
:imap <ESC>[H <C-o><Home>
:imap <ESC>[F <C-o><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 <C-o>b
:imap <ESC>f <C-o>el
:cmap <ESC>f el
endif
作爲一個小,但顯著獎金你得到Home/End鍵導航,但不退出insert
模式。測試10.8.5
。
正常模式下的'w'是逐字移動的最佳方式。 – alternative 2011-03-17 21:41:57
您可以在插入模式下使用^ O來運行一個正常模式命令並保持插入模式,例如^ Ow。 – 2011-03-17 22:58:21