Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 588
kerkeslager Avatar asked Oct 25 '10 16:10

kerkeslager


2 Answers

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.)

like image 50
Pi Delport Avatar answered Nov 10 '22 04:11

Pi Delport


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

like image 44
OmnipotentEntity Avatar answered Nov 10 '22 03:11

OmnipotentEntity