Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What mode does vim enter when completion menu is up?

Tags:

vim

I recently changed my arrow keys to map to no-op to force myself to use vim navigation properly. When using word completion in vim a word-list of possible completions pops up. I used to navigate this by using the arrow keys, but now have to use the same mapping as the completion initiation to iterate through.

When this menu pops up, does vim stay in insert mode, change to a different mode or does it enter a modified insert mode (similar to what paste-toggle does) that I can alter the j and k mappings to move through the list?

If not is there a way of calling a method on pop-up open and close?

like image 613
cdbitesky Avatar asked Jul 21 '13 22:07

cdbitesky


People also ask

What are the modes of vim?

vim has two "modes": COMMAND mode and INSERT mode. In COMMAND mode, you execute commands (like undo, redo, find and replace, quit, etc.). In INSERT mode, you type text. There is a third mode, VISUAL mode, that is used to highlight and edit text in bulk.

How do I go to normal mode in Vim?

By default, Vim starts in “normal” mode. Normal mode can be accessed from other modes by pressing Esc or <C-[> .


1 Answers

The popup menu of insert mode completion candidates belongs to insert mode, there's no special submode for it. To differentiate, you have to use map expressions :inoremap <expr> with a condition on pumvisible(). E.g. to remap j to select the next completion candidate:

:inoremap <expr> j pumvisible() ? '<C-n>' : 'j'

Note that with this, you won't be able to type candidate names containing j to drill down and select from the list (which is especially useful with :set completeopt+=longest).

like image 111
Ingo Karkat Avatar answered Oct 24 '22 07:10

Ingo Karkat