No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
− | {{category=C++}} |
||
In this tip I'll show you how to setup C++ code completion in Vim. |
In this tip I'll show you how to setup C++ code completion in Vim. |
||
Revision as of 22:44, 12 October 2008
In this tip I'll show you how to setup C++ code completion in Vim.
1. First install OmniCppComplete: [1]
2. Now make a directory that will hold your ctags. I have that in: ~/.vim/tags
3. Create stdc++ tags: Download and unpack modified headers from [2] to ~/.vim/tags/cpp_source
4. Run ctags:
$ cd ~/.vim/tags $ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ cpp_src $ mv tags cpp
5. Add additional tags (change to your system/likings):
$ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/GL/ && mv tags gl # for OpenGL $ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/SDL/ && mv tags sdl # for SDL $ ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ /usr/include/qt4/ && mv tags qt4 # for QT4
6. Edit your ~/.vimrc and change to your system/likings:
" " configure tags - add additional tags here or comment out not used ones " set tags+=~/.vim/tags/cpp set tags+=~/.vim/tags/gl set tags+=~/.vim/tags/sdl set tags+=~/.vim/tags/qt4 " build tags of your own project with CTRL+F12 map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> " " OmniCppComplete " let OmniCpp_NamespaceSearch = 1 let OmniCpp_GlobalScopeSearch = 1 let OmniCpp_ShowAccess = 1 let OmniCpp_MayCompleteDot = 1 let OmniCpp_MayCompleteArrow = 1 let OmniCpp_MayCompleteScope = 1 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] " automatically open and close the popup menu / preview window autocmd CursorMovedI * if pumvisible() == 0|pclose|endif autocmd InsertLeave * if pumvisible() == 0|pclose|endif set completeopt=menuone,menu,longest,preview
Additional information
It is nice to have the headers of the used libs really on your system so the preview window has something to show.