ctags for autocompleting c++ library functions in vim

守給你的承諾、 提交于 2019-12-13 08:01:58

问题


After following some tutorials i tried to use exuberant ctags to autocomplete e.g. openGL functions. I used the command

ctags -R --languages=C,C++ --c++-kinds=+p --fields=+iaS --extra=+q ./

in the directory where the freeglut.h, glew.h etc resides. Then copying this to a directory pointed by in the .vimrc file (with 'set tags+=./myTag/tags' in my .vimrc) When I try to autocomplete some glut functions i dont get the funciton parameters listed, only the function itself gets completed, but without the parameters.

On the other hand, when Im applying the ctags command above to a .cpp file in the same directory where my main file resides it autocompletes with the function parameters. Im probably missing some essential information here.


回答1:


Firstly, I'm tired of managing ctags by hand, and I wrote plugin Indexer for that. It provides painless automatic tags generation and keeps tags up-to-date. For detailed information, see the article: Vim: convenient code navigation for your projects, which explains the usage of Indexer + Vimprj thoroughly.

And secondly, for code autocompletion, I suggest you to use clang_complete. It provides real, perfect C/C++/Objective-C completion from true compiler, not ugly method by tags.




回答2:


In your .vimrc file, before adding the tag files, add the directory. So if you added the tage in $HOME/.vim/tags directory you need to add the following line set tags=~/.vim/tags

The section (in your .vimrc) referred to OmniCppComplete may be something like this:

" configure tags - add additional tags here or comment out not-used ones
    " Setting the directory...
    set tags=~/.vim/tags 
        " Adding the tag files
        set tags+=~/.vim/tags/cpp
        set tags+=~/.vim/tags/gl
        set tags+=~/.vim/tags/sdl
        set tags+=~/.vim/tags/qt4
" set tags+=/home/yonatan/.vim/tags/standard 
" build tags of your own project with Ctrl-F12
map <C-F12> :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>

" OmniCppComplete
let OmniCpp_NamespaceSearch = 1
let OmniCpp_GlobalScopeSearch = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
let OmniCpp_MayCompleteDot = 1 " autocomplete after .
let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" automatically open and close the popup menu / preview window
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
set completeopt=menuone,menu,longest,preview


来源:https://stackoverflow.com/questions/12383624/ctags-for-autocompleting-c-library-functions-in-vim

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!