views:

114

answers:

2

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?

+6  A: 

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

OmnipotentEntity
And `CTRL-Y` to accept, `CTRL-E` to discard.
Benoit
+8  A: 

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.

Piet Delport
A problem one might run into while using this method is that he/she might want to continue typing after invoking the completion menu and the letters he/she wish to type are 'j' or 'k'. Just good to know what the consequences are in case problems arise in the future.
tinifni
@tinifni One can use `<C-v>j` and `<C-v>k` to do it.
ZyX