Home Explore Blog CI



neovim

10th chunk of `runtime/doc/insert.txt`
d807b09c65a37bcddf66485d51dc6f39733941e4bef450bc0000000100000fa4
 'wrap' is set
(and the line changes length to become shorter or wider than the width of the
screen).  In other cases spaces may be inserted to avoid following characters
to move.

This mode is very useful for editing <Tab> separated columns in tables, for
entering new data while keeping all the columns aligned.

==============================================================================
7. Insert mode completion				*ins-completion*

In Insert and Replace mode, there are several commands to complete part of a
keyword or line that has been typed.  This is useful if you are using
complicated keywords (e.g., function names with capitals and underscores).

Completion can be done for:

1. Whole lines						|i_CTRL-X_CTRL-L|
2. keywords in the current file				|i_CTRL-X_CTRL-N|
3. keywords in 'dictionary'				|i_CTRL-X_CTRL-K|
4. keywords in 'thesaurus', thesaurus-style		|i_CTRL-X_CTRL-T|
5. keywords in the current and included files		|i_CTRL-X_CTRL-I|
6. tags							|i_CTRL-X_CTRL-]|
7. file names						|i_CTRL-X_CTRL-F|
8. definitions or macros				|i_CTRL-X_CTRL-D|
9. Vim command-line					|i_CTRL-X_CTRL-V|
10. User defined completion				|i_CTRL-X_CTRL-U|
11. omni completion					|i_CTRL-X_CTRL-O|
12. Spelling suggestions				|i_CTRL-X_s|
13. keywords in 'complete'				|i_CTRL-N| |i_CTRL-P|
14. contents from registers				|i_CTRL-X_CTRL-R|

Additionally, |i_CTRL-X_CTRL-Z| stops completion without changing the text.

All these, except CTRL-N and CTRL-P, are done in CTRL-X mode.  This is a
sub-mode of Insert and Replace modes.  You enter CTRL-X mode by typing CTRL-X
and one of the CTRL-X commands.  You exit CTRL-X mode by typing a key that is
not a valid CTRL-X mode command.  Valid keys are the CTRL-X command itself,
CTRL-N (next), and CTRL-P (previous).

To get the current completion information, |complete_info()| can be used.
Also see the 'infercase' option if you want to adjust the case of the match.

When inserting a selected candidate word from the |popup-menu|, the part of
the candidate word that does not match the query is highlighted using
|hl-ComplMatchIns|.  If fuzzy is enabled in 'completeopt', highlighting will
not be applied.

							*complete_CTRL-E*
When completion is active you can use CTRL-E to stop it and go back to the
originally typed text.  The CTRL-E will not be inserted.

							*complete_CTRL-Y*
When the popup menu is displayed, CTRL-Y stops completion and accepts the
currently selected entry.  Typing a space, Enter, or some other unprintable
character will leave completion mode and insert that typed character. If you
want to use <Enter> to accept a completion item, use this mapping: >vim
    inoremap <expr> <cr> pumvisible() ? '<c-y>' : '<cr>'

When the popup menu is displayed there are a few more special keys, see
|popupmenu-keys|.

Note: The keys that are valid in CTRL-X mode are not mapped.  This allows for
`:map <C-F> <C-X><C-F>` to work.  The key that ends CTRL-X mode (any key that
is not a valid CTRL-X mode command) is mapped. Also, 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

Title: Insert Mode Completion Details
Summary
This section details various Insert and Replace mode completion commands, including options for whole lines, keywords from different sources (current file, dictionary, thesaurus, included files, tags, file names, definitions/macros, command-line, user-defined, omni-completion, spelling suggestions, and registers). It explains CTRL-X mode, a sub-mode for most completion types, and how to enter/exit it. Also covered are special keys like CTRL-E and CTRL-Y for stopping or accepting completion, considerations for mappings, and the behavior of CTRL-R within CTRL-X mode. Note that Insert mode can't be used recursively and buffer text cannot be changed while completion is active.