If you're a (Neo)Vim user and you're not familiar with Ctrl-p
, well, Hallelujah, you just learned one of Vim's best features. In INSERT mode, type a part of a word and press Ctrl-p
and Vim will attempt to complete the word by matching any words that exist in all your open buffers. This is, as you'll quickly find, incredibly useful for matching method or variable names when you're programming, and long words or titles when you're writing. If that's all you ever learn about Vim's completion modes, you're doing okay. However, Vim has several other completion modes and some of them are worth learning too.
I should first admit that this is cribbed directly from Drew Neil's superb Practical Vim - I've tried to read several books about Vim over the years, but this is the first that I've got through.
Ctrl-n | generic keywords |
Ctrl-x Ctrl-n | current buffer keywords |
Ctrl-x Ctrl-i | included file keywords |
Ctrl-x Ctrl-] | tags file keywords |
Ctrl-x Ctrl-k | dictionary lookup |
Ctrl-x Ctrl-l | whole line completion |
Ctrl-x Ctrl-f | filename completion |
Ctrl-x Ctrl-o | Omni-completion |
I was already aware of Ctrl-x Ctrl-f
- that's a beautiful thing, to be able to complete filenames from your directory structure. And I immediately tested dictionary completion Ctrl-x Ctrl-k
for the word "Hallelujah" which I've always had trouble remembering how to spell.
Which of these are useful to you will depend on how you use Vim: it's very rare for me to need a method from an included file (although that may change) so I'm likely to forget Ctrl-x Ctrl-i
, but the filename completion has already glued itself into my head. Try them all out and see which is most useful to you.
For further reading on the topic, open vim and type :help ins-completion
.