简体   繁体   中英

Vim C++ auto complete

How do I enable auto completion in Vim?

I tried to do this one, but I'm not proficient with the vimrc file, etc., so it didn't work out. Can you give me step by step instructions on how to do this?


Edit

I tried installing OmniCppComplete. Followed the instructions, but when I try to use it I get the following error:

Error detected while processing function omni#cpp#complete#Main..24_InitComplete:

line 24:

E10: \\ should be followed by /, ? or &

Detailed instructions Auto complete (archive.org) Type in first few characters and press Ctrl->P(for backward search) or Ctrl->N(for forward search), list down all options available or completes it.

I use vim7.2 (auto complete was introduced in vim7) and these controls work just fine.

Vim by default will do completion based on words in the file using Ctrl-N or Ctrl-P, which is handy for recently referenced local variables etc, and works for code in any language or even ordinary text (handy for completing difficult to spell names). However it doesn't do this semantically or with reference to what actual types you're allowed in the particular context you're writing. For this you will need to install ctags , and then in /usr/include type:

ctags -f ~/.vim/stdtags -R --c++-kinds=+p --fields=+iaS --extra=+q .

And then add this to your .vimrc:

set nocp
filetype plugin on
map <C-L> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR>

set tags=~/.vim/stdtags,tags,.tags,../tags

autocmd InsertLeave * if pumvisible() == 0|pclose|endif

That will also make Ctrl-L reload tags, and thus pick up new autocomplete tags, from the current directory.

My favorite is clang_complete here . It's very easy to install and the default configuration in the ReadMe document works good. You don't need to generate the tags, It automatically show the complete options when available. It also can highlight the syntax errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM