created 2001 · complexity basic · author Jamo.sp · version 5.7
In insert mode, type the first couple of characters of a word, then press:
- Ctrl-N to insert the next matching word; or
- Ctrl-P to insert the previous matching word.
This is particularly useful when entering the names of variables in a program.
The 'complete'
option controls where the keywords are searched (include files, tag files, buffers, and more).
The 'completeopt'
option controls how the completion occurs (for example, whether a menu is shown).
See also[]
- Using abbreviations defining abbreviations for commonly-used text
- 91 Dictionary completions
- 102 Smart mapping for tab completion
- 295 Line/word/file/whatever completion
- 481 Abbreviations only on shortcut
- 498 Completion using a syntax file
- 566 Autocomplete with TAB when typing words
- 765 Complete from filetype syntax file
- 968 Custom keyword completion
- 1228 Improve completion popup menu
- 1386 Make Vim completion popup menu work just like in an IDE
- 1486 Omni completion popup menu
- 1591 Omni completion
- 1608 C++ code completion
References[]
- :help i_CTRL-N
- :help i_CTRL-P
- :help ins-completion
- :help 'complete'
- :help 'completeopt'
- :help i_CTRL-X_CTRL-P
- :help i_CTRL-X_CTRL-N
Comments[]
Also see script#182 and script#73
Completion such as this is also why it is a good idea to have descriptive variable names, so you can easily tell if you have the completion you were after.
It's completion that made me unable to use Visual Studio's editor (which has some completion, but it's not as good) anymore. I get lots of use out of:
- File completion: <C-X><C-F>
- Line completion: <C-X><C-L>
- Omni completion: <C-X><C-O>
If you have several words you would like to complete, you can use Ctrl-X Ctrl-P to extend the match. For example, suppose a line exists in your file:
$res = mysql_query($q) or die(mysql_error());
You want to type the line:
$result = mysql_query($q) or die(mysql_error());
Type:
$result = my
Keep pressing Ctrl-P until you get to mysql_query.
Then pressing Ctrl-X Ctrl-P will give:
$result = mysql_query($q