OmniComplete 和 Vim 问题

发布于 2024-12-23 09:11:40 字数 2029 浏览 1 评论 0原文

我正在尝试让omnicomplete适用于C++,虽然一切似乎都按顺序进行,但当我将omnifunc重置为omnifunc=omni#cpp#complete#Main时,该插件无法识别omn​​ifunc,并且我收到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千纸鹤 2024-12-30 09:11:40

显然,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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文