It’s been a long time since my friend Thiago wisely taunted me to start using clang on vim scripts (and on everywhere else too). I finally made some time to take a look on it, mostly because of this excellent rant on the subject.
The core of the problem is that OmniCppComplete isn’t a compiler and you can’t expect something that isn’t a compiler to fully understand code. — Guy Rutenberg
So, here comes my quick recipe to get it running on vim7.3+ with python support. I assume you already have your vim setup under revision control and use pathogen to group multiple bundles (these requirements are so lame that I refuse to spend any time to justify them ).
- install clang and partners
12# on Ubuntu 11.10$ sudo apt-get install clang
- remove omnicppcomplete bundle as in this answer
12345$ cd ~/.vim$ git rm --cached bundle/OmniCppComplete$ git config -f .git/config --remove-section submodule.bundle/OmniCppComplete$ git config -f .gitmodules --remove-section submodule.bundle/OmniCppComplete$ git commit -a -m "remove omnicppcomplete"
- create new bundle
1$ git submodule add https://github.com/Rip-Rip/clang_complete.git bundle/clang_complete
- fine tune clang_complete settings
123456# the script below is directly included by ~/.vimrc$ cat >> ~/.vim/setup.vim" Avoid freezing on offending codelet g:clang_user_options='|| exit 0'let g:clang_close_preview=1^D
1$ git commit -a -m "installed clang_complete"
Done! C/C++ code completion at the tip of your fingers.
Just as disclaimer, there are still some rough edges on the clang_complete script, e.g.
- the preview window is not informative at all (better to disable with :set completeopt-=preview)
- you need to manually reload source files after updating .clang_complete files (just a problem on initial setups)
However, these do not spoil the overall experience at all. The next step will be to install Ubuntu 12.04 for libclang-dev usage (much faster than using clang command).