Code completion (IntelliSense) for C++ in Vim with OmniCppComplete
C++ autocompletion is possible with VIM.

This is officially the coolest tech discovery I’ve made this year.
And it’s easy to setup.
Here’s how to configure C++ IntelliSense for Vim, with an example that demonstrates how to enable code completion for the the C++ Standard Template Library (STL).
1. Download
You need the following:
2. Install
With Ubuntu 8.10 you can install Vim and Exuberant Ctags like so:
sudo apt-get install vim exuberant-ctags
Install OmniCppComplete by downloading the plugin and extracting it to your Vim settings (~/.vim/) folder.
Then open Vim, and type the following:
:helptags $HOME/.vim/doc
3. Configure Vim
Add the following to your .vimrc file (you only need the required and ctags sections, but I included options I found useful – hack as you please):
" --- OmniCppComplete ---
" -- required --
set nocp " non vi compatible mode
filetype plugin on " enable plugins
" -- optional --
" auto close options when exiting insert mode
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
set completeopt=menu,menuone
" -- configs --
let OmniCpp_MayCompleteDot = 1 " autocomplete with .
let OmniCpp_MayCompleteArrow = 1 " autocomplete with ->
let OmniCpp_MayCompleteScope = 1 " autocomplete with ::
let OmniCpp_SelectFirstItem = 2 " select first item (but don't insert)
let OmniCpp_NamespaceSearch = 2 " search namespaces in this and included files
let OmniCpp_ShowPrototypeInAbbr = 1 " show function prototype (i.e. parameters) in popup window
" -- ctags --
" map <ctrl>+F12 to generate ctags for current folder:
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR><CR>
" add current directory's generated tags file to available tags
set tags+=./tags
4. Generate Ctags
To generate the ctags and enable code completion for the code you are currently working on (everything in your current working directory and its sub-directories), you can simply hit CTRL+F12.
To understand how this works, check out the key-binding you enabled in your .vimrc file in step 3 of this tutorial.
To enable code completion for an external library, you need to:
- Do pre-processing on the library (if needed).
- Generate a ctags file for the library.
- Tell Vim where to find the ctags file.
I will demonstrate using the Standard Template Library (STL) as an example.
Start by downloading the STL source and extracting it somewhere meaningful (e.g. /usr/local/lib/stl3.3).
For most libraries you can skip the first step, but some libraries (like the STL) will need a little pre-processing because of the complexity introduced by macros.
Change to the directory where you extracted the STL source, and run the following:
$ find . -name '*.h' | xargs sed -i 's/__STL_BEGIN_NAMESPACE/namespace std {/'
$ find . -name '*.h' | xargs sed -i 's/__STL_END_NAMESPACE/}/'
Now we’re ready to generate the ctags. In the directory where you extracted the STL source, run:
$ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q ./
This will create a file called ‘tags’ in the current directory. Rename and move the file somewhere meaningful, e.g.:
$ mkdir ~/.myTags
$ mv tags ~/.myTags/std3.3.tags
Lastly, tell Vim where to find the tags by adding the following to your .vimrc file:
set tags+=~/.myTags/std3.3.tags
And voila.



Tags: autocompletion, C++, code completion, IntelliSense, Linux, omnicppcomplete, UNIX, vim
October 9th, 2009 at 8:40 pm
This is officially the coolest tech blog discovery I’ve made this year
.
—- I mean it. Great Post. Thanks.
please also put the info on how to set the background to black by default(although this can be done by a bit googling but when seeing for the first time the code completion , the adernaline goes much higher when seen on black background).
November 11th, 2009 at 12:48 pm
I follow your tutorial but I’ve got an error in the .vimrc parsing. line 19:
E337: Menu not found – check menu names
I’m on Ubuntu 8.10
Tnx
November 11th, 2009 at 1:25 pm
@Marco
I was also using Ubuntu 8.10 when I wrote this tutorial.
What is the text at line 19 in your .vimrc file?
November 11th, 2009 at 1:28 pm
@shankar
You need to change your VIM colorscheme to set the background to black.
Try putting something like
in your .vimrc file.
November 11th, 2009 at 3:02 pm
Sorry, my fault. Works fine!
December 23rd, 2009 at 9:13 pm
Wow! This is one of the most useful set of instructions that I’ve read in a while. Kudos, man! BTW, the ctags file I generated for the entire boost library was 1.4GB!
December 25th, 2009 at 9:16 am
@tony
1.4GB… hectic.
It may be that OmniCppComplete only uses a subset of the generated CTAGS content.
perhaps it will be possible to get the size down by playing with the CTAGS options or post-processing the generated file??
January 5th, 2010 at 10:06 pm
Hey,
Great work !
Same problem with boost template library..: it appears that ctags definitly have problems with templates.
The generate ctags file is huge and the auto-completion in gvim for boost:: is very slow …
does anyone fix this ?
++
Nice tuto again !
March 4th, 2010 at 9:33 pm
Hi there,
really like this article and it help me a lot. but there is one thing might worth be mentioned :
for the command to generate tag $ ctags -R –c++-kinds=+p –fields=+iaS –extra=+q ./ , I think instead of use “./” ,the absolute path should be used otherwise when you move the generated tags to elsewhere in the file system, ctags will suppose that all the std files all in the same directory with the tags file .
Just my thoughts, it might be other explaination for this issue .
anyway, thanks again.
August 27th, 2010 at 4:26 pm
Hi! It is a great article! Thanks a lot!
But I think you have fogot about headers without extention *.h in stl, like string, memory, valarray
$ find . -name ‘*.h’ | xargs sed -i ‘s/__STL_BEGIN_NAMESPACE/namespace std {/’
$ find . -name ‘*.h’ | xargs sed -i ‘s/__STL_END_NAMESPACE/}/’
March 9th, 2011 at 12:13 pm
Hi.
Thanks for the article.
Please be carefull to a tiny detail :
- “voila” is a French word, that mean exactly what you think (something like “ta-da”)
- “viola” is a French word too. It comes from the verb “violer” which means “to rape”.
March 9th, 2011 at 4:01 pm
@Yaman
Oops!
Thanks for pointing that out.
September 17th, 2011 at 11:31 am
omnicppcomplete doesn’t seem to know what a smart pointer is. Does anyone know how to solve this:
class C {
public: int get_int() {return 10;}
};
…
shared_ptr cp(new C);
cp-> // complete shows get_int() as well here, not just the shared_ptr interface!!!
thanks in advance,
cheers,
alex
December 9th, 2012 at 3:57 am
Great article.
March 8th, 2013 at 6:53 pm
Nice one.
Thank you