vim+omicppcomplete

这里详细介绍了如何将stdlib header加入到ctags中:

首先,将c++标准库的头文件cp到.vim目录下,然后生成ctags:

$ cp -R /usr/include/c++/$GCC_VERSION ~/.vim/cpp_src
# it is not necessary to rename headers without an extension
# replace the "namespace std _GLIBCXX_VISIBILITY(default)" with "namespace std"
$ find . -type f | xargs sed -i 's/namespace std _GLIBCXX_VISIBILITY(default)/namespace std/'
$ ctags -f cpp_tags -R --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ -I _GLIBCXX_NOEXCEPT cpp_src

接着,将新生成的cpp_tags 加入到ctags搜索路径中:

" configure tags - add additional tags here or comment out not-used ones
set tags+=~/.vim/cpp_tags
" build tags of your own project with Ctrl-F12
map  :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q -I _GLIBCXX_NOEXCEPT .

" 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 ::
" also necessary for fixing LIBSTDC++ releated stuff
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

实际操作过程中,发现ctags运行是没啥问题,但vim打开时,有报错,原因很可能是ctags版本太旧没更新了,09年写的,那时候c++还是03的标准,现在基本上用的都是c++11以上的编译器了,所以ctags解析不了,最简单的解决办法是直接将copy一份比较旧的c++ header,然后再用ctags生成: https://www.vim.org/scripts/script.php?script_id=2358

refs:

1.  https://stackoverflow.com/questions/24489855/generate-ctags-for-libstdc-from-current-gcc

2.  https://www.vim.org/scripts/script.php?script_id=2358

 

你可能感兴趣的:(c,plus,plus)