Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim C++ auto complete

Tags:

c++

vim

unix

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 &

like image 211
Amir Rachum Avatar asked Aug 11 '10 12:08

Amir Rachum


People also ask

How do I autocomplete in Vim?

2.1. vimrc configuration file. Next, we'll enter a few characters of a word we need to write and press Ctrl-N to trigger autocompletion. We can select the preferable term from the list. Also, to see Vim's documentation on the autocomplete functionality, we can use :help i_CTRL-N.

Does Vim have intellisense?

The IDE or editor should help in a way to build programs. Vim helps in so many ways, and especially the auto-completion is provided by Vim, by default. But it does not give the intellisense which is beyond auto-completion. I think most of us know what is intellisense, which is provided by Visual Studio.

How do I use autocomplete in Neovim?

Vim-Go uses gopls for autocompletion. By default, it relies on Ctrl-x Ctrl-o to trigger it. To trigger it automatically in Neovim, use Deoplete.

What is Omnifunc Vim?

vim-text-omnicompleteThis plugin automatically sets the omni completion function ( omnifunc ) for files with the text filetype. As such, when editing text files, you will be able to use Ctrl x Ctrl o to show a list of autocomplete suggestions.


2 Answers

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.

like image 176
NeilDurant Avatar answered Oct 03 '22 05:10

NeilDurant


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.

like image 43
DumbCoder Avatar answered Oct 03 '22 06:10

DumbCoder