开发者

vim word completion navigating with 'j' and 'k'

In vim, I use Ctrl-n to word complete while in insert mode开发者_运维技巧. If there is more than one possible match, I get a dropdown from which I can select one of the possible matches using the arrow keys.

However, I don't want to use the arrow keys; I want to use the 'j' and 'k' keys. But when I type 'j' or 'k', it inserts the letters instead of going up or down in the dropdown. Is there a way I can configure vim to do this the way I want?


See :hpopupmenu-keys.

There is no special set of mappings for the popup menu sub-mode, but you can make a conditional insert-mode mapping:

inoremap <expr> j pumvisible() ? "\<C-N>" : "j"
inoremap <expr> k pumvisible() ? "\<C-P>" : "k"

This makes j/k navigate the popup menu like <C-N>/<C-P>, while it is visible.

Addendum: If you want to be able to hold in control while you type j and k, you can replace them with <C-J> and <C-K>, respectively. (See mwcz's comment to this answer.)


I don't know of a way how to do it with j and k. You're in insert mode, they don't work.

But, I have another way for you, Ctrl+N works the same as Tab, and you can use Shift-Tab to go down the list and Tab to go up. It's easier than using the arrow keys. But not as nice as j and k would be.

Or you can just use Ctrl+N and Ctrl+P


SuperTab (http://www.vim.org/scripts/script.php?script_id=1643) may help you. Once installed, you can use Tab and Tab-Shift to navigate the pop up menu.

See this doc also: http://vim.wikia.com/wiki/Omni_completion_popup_menu

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜