OmniComplete 和 Vim 问题
我正在尝试让omnicomplete适用于C++,虽然一切似乎都按顺序进行,但当我将omnifunc重置为omnifunc=omni#cpp#complete#Main时,该插件无法识别omnifunc,并且我收到 pattern not found
错误。我已经安装了 Ctags 并将其放入 .vim/
中,同时将 cpp_src
添加到 .vim/tags
并运行必要的命令。 (请参阅此处了解更多信息)
问题是,无论我尝试什么,我仍然收到此错误。我该怎么做才能让它发挥作用?我以前尝试过这个,第一次只是很头痛,导致我无法让它工作。不过,这一次我下定决心了。
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
一如既往,非常感谢任何帮助。
更新
发布我的 Ctags 文件以供其他人检查,以防出现问题:
ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显然,Vim 找不到你的标签文件。您的命令
ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
将在当前目录中创建tags
文件。确保这就是您想要的。请执行以下命令:
:set Tags?
并确保您的标签文件出现在结果列表中。您还可以将光标放在任何符号(例如某个类名)上,然后按
Ctrl-]
。如果你的tags
没问题,Vim 将跳转到这个符号定义。如果不是,那么,omnicppcomplete
当然将无法工作。 (我使用omnicppcomplete
一年多了,它有效。对于复杂的类/结构来说并不完美,但有效。)最后,检查 我的答案在这里,因为我建议完全相同:要获得完美的 C/C++/Objective-C 代码完成,您应该使用 Clang Complete(这种完成不需要
ctags
)。如果您希望存在标签(例如,轻松跳转到符号定义),请使用 Indexer 插件。
Obviously, Vim can't find your tags file. Your command
ctags -R --c++-kinds=+p --fields-+iaS --extra=+q .
will createtags
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 yourtags
is OK. If it is not, then, of course,omnicppcomplete
will not work. (I useomnicppcomplete
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.