See the Elephant

1992生まれのプログラマが書くエンジニアブログ

vimのキーバインド<C-j>がinsertモード移行からmapできない時の解決方法

背景

vimとTmuxをシームレスに移動するためのプラグインを真似したかった.

vimの<C-j>をremapできなかったので, その対策を記す.

やりたかったこと

vim の normalモードで<C-j>に他のキーバインドを当てたい.

できなかったこと

normalモードで<C-j>を入力するとinsertモードに移行する.
:map <C-j><Plug>IMAP_JumpForwardが出力される.

解決方法

$HOME/.vim/plugin/imaps.vimの480行目あたりを編集する.
imap, nmap, vmapコメントアウトする.

" Default maps for IMAP_Jumpfunc {{{
" map only if there is no mapping already. allows for user customization.
" NOTE: Default mappings for jumping to the previous placeholder are not
"       provided. It is assumed that if the user will create such mappings
"       hself if e so desires.
if !hasmapto('<Plug>IMAP_JumpForward', 'i')
  " imap <C-J> <Plug>IMAP_JumpForward コメントアウト
 endif
if !hasmapto('<Plug>IMAP_JumpForward', 'n')
  " nmap <C-J> <Plug>IMAP_JumpForward コメントアウト
endif
if exists('g:Imap_StickyPlaceHolders') && g:Imap_StickyPlaceHolders
 if !hasmapto('<Plug>IMAP_JumpForward', 'v')
  " vmap <C-J> <Plug>IMAP_JumpForward コメントアウト
 endif
else
 if !hasmapto('<Plug>IMAP_DeleteAndJumpForward', 'v')
  " vmap <C-J> <Plug>IMAP_DeleteAndJumpForward コメントアウト
 endif
endif
" }}}

上記でできた.