Home Explore Blog CI



neovim

19th chunk of `runtime/doc/insert.txt`
90a1a69cbd823c7479ad370b1cf3590ff3c230a94e3e606a0000000100000fa1
 completefunc=CompleteMonths
<

INSERT COMPLETION POPUP MENU				*ins-completion-menu*
							*popupmenu-completion*
Vim can display the matches in a simplistic popup menu.

The menu is used when:
- The 'completeopt' option contains "menu" or "menuone".
- The terminal supports at least 8 colors.
- There are at least two matches.  One if "menuone" is used.

The 'pumheight' option can be used to set a maximum height.  The default is to
use all space available.
The 'pumwidth' option can be used to set a minimum width.  The default is 15
characters.

							*compl-states*
There are three states:
1. A complete match has been inserted, e.g., after using CTRL-N or CTRL-P.
2. A cursor key has been used to select another match.  The match was not
   inserted then, only the entry in the popup menu is highlighted.
3. Only part of a match has been inserted and characters were typed or the
   backspace key was used.  The list of matches was then adjusted for what is
   in front of the cursor.

You normally start in the first state, with the first match being inserted.
When "longest" is in 'completeopt' and there is more than one match you start
in the third state.

If you select another match, e.g., with CTRL-N or CTRL-P, you go to the first
state.  This doesn't change the list of matches.

When you are back at the original text then you are in the third state.  To
get there right away you can use a mapping that uses CTRL-P right after
starting the completion: >
	:imap <F7> <C-N><C-P>
<
						*popupmenu-keys*
In the first state these keys have a special meaning:
<BS> and CTRL-H   Delete one character, find the matches for the word before
		  the cursor.  This reduces the list of matches, often to one
		  entry, and switches to the second state.
Any non-special character:
		  Stop completion without changing the match and insert the
		  typed character.

In the second and third state these keys have a special meaning:
<BS> and CTRL-H   Delete one character, find the matches for the shorter word
		  before the cursor.  This may find more matches.
CTRL-L		  Add one character from the current match, may reduce the
		  number of matches.
any printable, non-white character:
		  Add this character and reduce the number of matches.

In all three states these can be used:
CTRL-Y		  Yes: Accept the currently selected match and stop completion.
CTRL-E		  End completion, go back to what was there before selecting a
		  match (what was typed or longest common string).
<PageUp>	  Select a match several entries back, but don't insert it.
<PageDown>	  Select a match several entries further, but don't insert it.
<Up>		  Select the previous match, as if CTRL-P was used, but don't
		  insert it.
<Down>		  Select the next match, as if CTRL-N was used, but don't
		  insert it.
<Space> or <Tab>  Stop completion without changing the match and insert the
		  typed character.

The behavior of the <Enter> key depends on the state you are in:
first state:	  Use the text as it is and insert a line break.
second state:	  Insert the currently selected match.
third state:	  Use the text as it is and insert a line break.

In other words: If you used the cursor keys to select another entry in the
list of matches then the <Enter> key inserts that match.  If you typed
something else then <Enter> inserts a line break.


The colors of the menu can be changed with these highlight groups:
Pmenu		normal item  |hl-Pmenu|
PmenuSel	selected item  |hl-PmenuSel|
PmenuSbar	scrollbar  |hl-PmenuSbar|
PmenuThumb	thumb of the scrollbar  |hl-PmenuThumb|

There are no special mappings for when the popup menu is visible.  However,
you can use an Insert mode mapping that checks the |pumvisible()| function to
do something different.  Example: >
	:inoremap <Down> <C-R>=pumvisible() ? "\<lt>C-N>" : "\<lt>Down>"<CR>

You can use of <expr> in mapping to have the popup menu used when typing a
character and some condition is met.  For example, for typing a dot: >
	inoremap <expr> . MayComplete()
	func

Title: Popup Menu Completion States, Keys, and Customization
Summary
This section describes the three states of Insert Completion Popup Menu and the meaning of different keys in each state, including <BS>, CTRL-H, CTRL-L, CTRL-Y, CTRL-E, <PageUp>, <PageDown>, <Up>, <Down>, <Space>, <Tab>, and <Enter>. It also mentions the highlight groups that control the menu's appearance: Pmenu, PmenuSel, PmenuSbar, and PmenuThumb. It explains how to use the pumvisible() function in Insert mode mappings to customize behavior when the popup menu is visible, and provides an example for mapping the <Down> key. Finally, it shows how to use an expression mapping to trigger completion on certain characters.