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

2019-01-31 03:19发布

问题:

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.



标签: vim ctags cscope