Keyword and Dictionary Word Completion
Vim offers a comprehensive suite of insertion-completion capabilities. From programming language-specific keywords to filenames, dictionary words, and even entire lines, Vim knows how to offer possible completions to partially entered text. Not only that, but Vim abstracts the semantic of dictionary-based completion to include completions based on synonyms for the completed word from a thesaurus!
In this section we look at the different completion methods, their syntaxes, and descriptions of how they work with examples. The methods of completion include:
Whole line
Current file keywords
dictionary
option keywordsthesaurus
option keywordsCurrent and included file keywords
Tags (as in ctags)
Filenames
Macros
Vim command line
User-defined
Omni
Spelling suggestions
complete
option keywords
Except for complete
keywords,
all completion commands start with CTRL-X. The second key specifically defines the type of completion
Vim attempts. For example, the command to autocomplete filenames is
CTRL-X CTRL-F. (Not all the commands are so
mnemonic, unfortunately.) Vim uses unmapped (default) keys, which
allows you to shorten most of these commands to just the second
keystroke by mapping the commands appropriately. (For instance, you
can map CTRL-X CTRL-N to just CTRL-N.)
All completion methods have virtually identical behavior: they cycle through a list of candidate completions as you retype the second keystroke. Thus, if you choose filename autocompletion through CTRL-X ...
Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.