Home Explore Blog CI



neovim

11th chunk of `runtime/doc/insert.txt`
31cd6eb5e34a78d5a994fd9377cf8b6d9f273be608e300c00000000100000fa2
 when doing completion
with 'complete' mappings apply as usual.

								*E565*
Note: While completion is active Insert mode can't be used recursively and
buffer text cannot be changed.  Mappings that somehow invoke ":normal i.."
will generate an E565 error.

The following mappings are suggested to make typing the completion commands
a bit easier (although they will hide other commands): >
    :inoremap <C-]> <C-X><C-]>
    :inoremap <C-F> <C-X><C-F>
    :inoremap <C-D> <C-X><C-D>
    :inoremap <C-L> <C-X><C-L>

As a special case, typing CTRL-R to perform register insertion (see
|i_CTRL-R|) will not exit CTRL-X mode.  This is primarily to allow the use of
the '=' register to call some function to determine the next operation.  If
the contents of the register (or result of the '=' register evaluation) are
not valid CTRL-X mode keys, then CTRL-X mode will be exited as if those keys
had been typed.

For example, the following will map <Tab> to either actually insert a <Tab> if
the current line is currently only whitespace, or start/continue a CTRL-N
completion operation: >

	function! CleverTab()
	   if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
	      return "\<Tab>"
	   else
	      return "\<C-N>"
	   endif
	endfunction
	inoremap <Tab> <C-R>=CleverTab()<CR>



Completing whole lines					*compl-whole-line*

							*i_CTRL-X_CTRL-L*
CTRL-X CTRL-L		Search backwards for a line that starts with the
			same characters as those in the current line before
			the cursor.  Indent is ignored.  The matching line is
			inserted in front of the cursor.
			The 'complete' option is used to decide which buffers
			are searched for a match.  Both loaded and unloaded
			buffers are used.
	CTRL-L	or
	CTRL-P		Search backwards for next matching line.  This line
			replaces the previous matching line.

	CTRL-N		Search forward for next matching line.  This line
			replaces the previous matching line.

	CTRL-X CTRL-L	After expanding a line you can additionally get the
			line next to it by typing CTRL-X CTRL-L again, unless
			a double CTRL-X is used.  Only works for loaded
			buffers.

Completing keywords in current file			*compl-current*

							*i_CTRL-X_CTRL-P*
							*i_CTRL-X_CTRL-N*
CTRL-X CTRL-N		Search forwards for words that start with the keyword
			in front of the cursor.  The found keyword is inserted
			in front of the cursor.

CTRL-X CTRL-P		Search backwards for words that start with the keyword
			in front of the cursor.  The found keyword is inserted
			in front of the cursor.

	CTRL-N		Search forward for next matching keyword.  This
			keyword replaces the previous matching keyword.

	CTRL-P		Search backwards for next matching keyword.  This
			keyword replaces the previous matching keyword.

	CTRL-X CTRL-N or
	CTRL-X CTRL-P	Further use of CTRL-X CTRL-N or CTRL-X CTRL-P will
			copy the words following the previous expansion in
			other contexts unless a double CTRL-X is used.

If there is a keyword in front of the cursor (a name made out of alphabetic
characters and characters in 'iskeyword'), it is used as the search pattern,
with "\<" prepended (meaning: start of a word).  Otherwise "\<\k\k" is used
as search pattern (start of any keyword of at least two characters).

In Replace mode, the number of characters that are replaced depends on the
length of the matched string.  This works like typing the characters of the
matched string in Replace mode.

If there is not a valid keyword character before the cursor, any keyword of
at least two characters is matched.
	e.g., to get:
	    printf("(%g, %g, %g)", vector[0], vector[1], vector[2]);
	just type:
	    printf("(%g, %g, %g)", vector[0], ^P[1], ^P[2]);

The search wraps around the end of the file, the value of 'wrapscan' is not
used here.

Multiple repeats of the same completion are skipped; thus a different match
will be inserted at each CTRL-N and CTRL-P (unless there is only one
matching keyword).

Single character matches are never included, as they usually just get in
the way

Title: Insert Mode Completion: Special Cases, Whole Lines, and Current File Keywords
Summary
This section covers advanced insert mode completion features in Vim. It details how mappings interact with completion, including a specific error (E565) when Insert mode is used recursively during completion. It provides example mappings to simplify completion commands and explains the behavior of CTRL-R for register insertion within CTRL-X mode. Furthermore, it includes a 'CleverTab' function example that dynamically inserts a tab or initiates CTRL-N completion based on the current line. Finally, it explains specific completion methods: completing whole lines (CTRL-X CTRL-L) and completing keywords from the current file (CTRL-X CTRL-N and CTRL-X CTRL-P), including how Vim determines the search pattern and handles matches.