VIM: More precise C/C++ code parsing solutions?

孤者浪人 提交于 2019-11-28 17:12:05

问题


Pre: I've been working in VIM for like a year already. Lots of great things: combinations, scripts. Whenever I'm editing something in a different editor, I feel sluggish/uncomfortable without VIM's navigation.

The problem: The thing that really bothers me most of all is source code navigation using existing tools (ctags, cscope). Often, ctags can't find the declaration of a variable, cscope as opposed to ctags finds all definitions with the same variable name. Same craziness with call tree navigation, finding forward declarations along with a single class definition etc. Compared to MS Intellisense, Visual Assist or even source code navigation in Eclipse, Exuberant Tags/cscope seems to be deprecated for at least 10 years.

I know there are tools like ViEMU, but they don't really solve the problem, since you lose lots of VIM's functionality.

The question: I was wondering if there is a tool that does the source parsing better, or there is some way to integrate source parsing engines like Intellisense into VIM ? Maybe there are commercial solutions or there are people who are ready to implement one ?

All the benefits of VIM seem to save less time than is being wasted while navigating to class definition, compared to Visual Assist, where it's done by a single Alt-G shortcut.


回答1:


Search and Call tree

You could try eclim, which is a way to use some Eclipse features in Vim.

For C/C++, it provides :

  • Context sensitive completion (although it is disabled on Windows because it is buggy)
  • Context sensitive search in Project files (through :CSearchContext)
  • Call tree for functions/methods (:CCallHierarchy)
  • Code Validation (:Validate)

It is not great, but it can help in some cases.

Code Completion

Regarding automatic code completion, I primarily use OmniCppComplete, which is using tags to provide Context aware code completion. It is not that bad.

As advised by Luc Hermitte, you can also use clang_complete which does not need ctags, but needs clang installed.




回答2:


Unfortunatelly, it is a real problem. ctags or cscope can hardly compete with Visual Studio code browsing - it actually uses a C++ compiler front-end to parse the code for the editor.



来源:https://stackoverflow.com/questions/5080211/vim-more-precise-c-c-code-parsing-solutions

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