Vim Tips Wiki
Tip 4 Printable Monobook Previous Next

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[]



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());


$result = my

Keep pressing Ctrl-P until you get to mysql_query.

Then pressing Ctrl-X Ctrl-P will give:

$result = mysql_query($q