Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim-style keys to navigate up and down in Omnicomplete box

Tags:

vim

One of the reasons that I moved from emacs to vim was to avoid awkward keybindings such as Ctrl+N and Ctrl+P for up and down. I would prefer more ergonomic keys like hjkl. However, I didn't find a way to navigate in Omnicomplete box without using arrow keys or Ctrl+N/P.

Does vim provide other keys for up and down?

enter image description here

like image 226
woodings Avatar asked Feb 20 '14 06:02

woodings


2 Answers

In the insert mode completion popup, any printable character is used to further restrict the list of matches, so there are only the <C-N> / <C-P> keys to choose different menu items.

If you can live with losing some completion keys, you can define the following mappings:

:inoremap <expr> j pumvisible() ? '<C-n>' : 'j'
:inoremap <expr> k pumvisible() ? '<C-p>' : 'k'
like image 134
Ingo Karkat Avatar answered Nov 15 '22 07:11

Ingo Karkat


I have the following mappings, which I'm very happy with:

" Move up and down in autocomplete with <c-j> and <c-k>
inoremap <expr> <c-j> ("\<C-n>")
inoremap <expr> <c-k> ("\<C-p>")

This is especially useful if you're using a plugin (such as Neocomplete, its older sibling Neocomplcache, or YouCompleteMe) that pops up autocomplete dialogues as soon as there might be something to complete to.

like image 32
OliverUv Avatar answered Nov 15 '22 08:11

OliverUv