From Vim Tips Wiki
created 2002 · complexity intermediate · author Nopik · version 6.0
In addition to any word completion you can use Ctrl-X completion mode to complete whole lines, filenames, keywords, and more. While entering text in insert mode, press Ctrl-X (written as <C-X> below), then another key to indicate the type of completion.
- <C-X><C-L> complete whole lines
- <C-X><C-P> complete words (<C-P> has the same effect; <C-X> is not needed)
- <C-X><C-F> complete file names
sspelling suggestions (after
:setl spellto enable spell checking)
While completion is active, type <C-P> or <C-N> to select the previous or next item.
For more information, see :help ins-completion.
For example, suppose the following text is entered:
this is first line second line is here
With the cursor on the empty third line, and while still in insert mode, pressing <C-X><C-L> will insert a copy of the second line. Select another line with <C-P> or <C-N>.
If "th" is typed at the start of the third line, pressing <C-X><C-L> will insert the first line because it starts with "th".
As an example of word completion, suppose "f" is typed at the start of the third line. Press <C-P> to complete the word using the previous occurrence that starts with "f"—that will insert "first". If you then press <C-X><C-P> the following word will also be inserted (the result will be "first line").