Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim auto-completion for C++'s #include clause

Tags:

c++

c

vim

I just installed omnicomplete plugin, does it support header auto completion?

When I typed #include <, is it possible to provide a list of header files to complete?

Many thanks!

like image 568
daisy Avatar asked Nov 19 '25 20:11

daisy


1 Answers

You can just use the vim autocomplete feature, which was introduced in vim7.

Just type in first few characters and press Ctrl->P(for backward search) or Ctrl->N(for forward search), vim lists down all options available or completes it.

And Yes it works even for header files.

To make this work you should install ctags In usr/include add:

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

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
like image 123
Alok Save Avatar answered Nov 21 '25 09:11

Alok Save



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!