vi/vim FAQ: How do I use the vim completion (word completion) feature?
When using the vi/vim editor I'm surprised how many people don't use its built-in vim completion (vim auto complete or vim code complete) feature.
vim word completion keystroke
Suppose you're in the vim editor and starting to type a long word that is already in your file -- why bother typing the whole word out? Just use the vim auto complete character sequence (
CTRL-P), and the odds are very good that vim will complete the word for you.
For instance imagine that the first paragraph above was in your current vim editor session, and you now wanted to type out the word "surprised". Would you type the entire word all over again? No, of course you wouldn't. :) Just type the characters "su" followed by
CTRL-P, and the vim complete functionality will do the rest of the word for you.
More vim word completion tips
That's the basic functionality, and maybe all you need to worry about. But if you really want to get into it there are several other features around this automatic word completion feature:
CTRL-Psearches backwards through the file for word matches,
CTRL-Ncan search forward through the file to look for matches.
- You can use the
:set ignorecaseoption to look for words regardless of their case. That is, if you start typing a string like "thi" and the word "Thimble" is in your file, vi will change your "thi" entry to "Thimble".
- Now imagine you wanted the word "thimble" with a lowercase 't'. You can use the
:set infercaseoption to fix this. With this option set vi will complete the new word as "thimble" instead of "Thimble".
There's even more power to this vim completion feature, but I'll skip the rest for now. Hopefully these tips will help save you a little typing time.