Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to autocomplete c or c++ keywords in vim

For example, when I type 'inclu', is there a method which can complete it to 'include'? Thank you.

like image 334
Aaron Avatar asked Jan 19 '23 06:01

Aaron


1 Answers

Most of vim's (complex) auto-completion is done via the ^X key mapping. ^X^] will autocomplete based on tags generated by ctags(1). ^X^P looks for previous keywords in the file that can be used for completion. ^X^K looks into a configurable dictionary for completion words. ^X^I looks into included files and pops up a menu for completing keywords from within those files. ^X^D completes from #define.

Perhaps the simplest way to get what you're after is to fully type #include <...> once in your file. The second file to be included could then be handled via #incl^X^P and then keep going.

If you want to put slightly more effort into it, create a ~/.vim/dict file with the keywords you want to autocomplete, add the file to the dictionary variable (:help dictionary), and use ^X^K to insert it.

like image 96
sarnold Avatar answered Jan 28 '23 05:01

sarnold