I'm trying to get omnicomplete to work for C++, and while everything seems to be in order, when I reset my omnifunc to be omnifunc=omni#cpp#complete#Main
, the plugin does not recognize the omnifunc, and I get a pattern not found
error. I've installed Ctags and put it in .vim/<name_of_dir>
, along with adding cpp_src
to .vim/tags
and running the necessary commands. (see here for more info)
The issue is that, no matter what I try, I still get this error. What can I do to get this working? I've tried this before, and the first time has just been a headache which resulted in me not being able to get it to work. This time, however, I'm determined.
VimRc
1 syntax on
2 set number
3 set autoindent
4 set ft=nasm
5 set ts=4
6 set nowrap
7 set nocp
8 filetype plugin on
9 map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
10
11 autocmd FileType cpp set omnifunc=omni#cpp#complete#Main
12
13 " configure tags - add additional tags here or comment out not-used ones
14 set tags+=~/.vim/tags/cpp
15 set tags+=~/.vim/tags/gl
16 set tags+=~/.vim/tags/sdl
17 " set tags+=~/.vim/tags/qt4
18 " " build tags of your own project with Ctrl-F12
19 map <C-F12> :!ctags -R --sort=yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
20 "
21 " " OmniCppComplete
22 let OmniCpp_NamespaceSearch = 1
23 let OmniCpp_GlobalScopeSearch = 1
24 let OmniCpp_ShowAccess = 1
25 let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
26 let OmniCpp_MayCompleteDot = 1 " autocomplete after .
27 let OmniCpp_MayCompleteArrow = 1 " autocomplete after ->
28 let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
29 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
30 " " automatically open and close the popup menu / preview window
31 au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif
32 set completeopt=menuone,menu,longest,preview
As always, any help is much appreciated.
Update
Posting my Ctags file for others to inspect in case there is an issue with that:
ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
Obviously, Vim can't find your tags file. Your command ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
will create tags
file in current directory. Make sure that this is what you want.
Please execute the following command:
:set tags?
and make sure your tags file is present in resulting list. You can also place cursor at any symbol (say, some class name) and press Ctrl-]
. Vim will jump to this symbol definition if your tags
is OK. If it is not, then, of course, omnicppcomplete
will not work. (I use omnicppcomplete
for more than year, and it works. Not perfectly with complicated classes/structs, but works.)
And, finally, check my answer here, because i would recommend absolutelly the same: to get perfect C/C++/Objective-C code completion you should use Clang Complete (no ctags
is needed for this kind of completion).
And if you want tags to be present (say, to easily jump to symbol definition), please use Indexer plugin.