Question

The IDE feature that I miss the most in emacs and vim are code navigation and find usages. Both of these editor have the following similar features for them:

  • Tags - identifiers from specified files are indexed and when you press shortcut on a word which is an identifier, you will be navigated there
  • CScope - it allows you to navigate to "usages" of an identifier

As far as I understand, both of these systems are very imprecise. If we have similar identifiers with the same name both tags and scope might mix them up. Are there any better alternatives and how precise they really are?

Was it helpful?

Solution 2

GNU Global, for example, allows duplicate identifiers, and you'll be able to select needed.

OTHER TIPS

I use cscope and semantic in Emacs. It is just enough for me.

In cscope the two function I heavily used are cscope-find-global-definition and cscope-find-this-symbol. The previous function is quite precise.

C-c s s         Find symbol. 
C-c s d         Find global definition.

As for semantic(dynamic index, do not need to generate TAGS).

(global-set-key [f8] 'semantic-ia-fast-jump) ;; jump to definition.
(global-set-key [S-f8]                       ;; jump back
                (lambda ()
                  (interactive)
                  (if (ring-empty-p (oref semantic-mru-bookmark-ring ring))
                     (error "Semantic Bookmark ring is currently empty"))
                  (let* ((ring (oref semantic-mru-bookmark-ring ring))
                         (alist (semantic-mrub-ring-to-assoc-list ring))
                         (first (cdr (car alist))))
                    (if (semantic-equivalent-tag-p (oref first tag)
                                                   (semantic-current-tag))
                        (setq first (cdr (car (cdr alist)))))
                    (semantic-mrub-switch-tags first))))

There are many programs that output ctags-compatible tags files. They are often language-specific because of some low level limitations in ctags but neither they nor ctags help you when you have multiple methods with the same name because these tools only do the indexing part of the job. Searching through the index is actually Vim's job and, because it is a freaking text editor and not an IDE it has zero mean to decide which method declaration is the right one.

Fortunately, Vim shows an actionable list when there are multiple hits. But that's how far you can go.

Cscope is a little smarter than ctags and, when used from Vim, does the searching as well as the indexing. But, like ctags, cscope is still a code indexer.

It's actually possible to use both at the same time with set cscopetags but it won't help with your naming issue.

You could try GNU Global. But it doesn't support JavaScript so I've never really used it long enough to make an opinion.

IDEs usually do their magic through language-specific parsers/static analysis tools that run in the background against your code. Vim has at least one limitation and one feature that make it hard to even imagine it ever reaching the level of code awareness that you seem to be looking for:

  1. Vim is not multithreaded. So it can't run a static analysis tool in the background.

  2. Vim supports hundreds of languages. Providing that kind of feature for that many languages would be impossible for any organization of any size.

But none of this is a problem for me, because Vim is not an IDE.

And because I don't have multiple methods with the same name in my projects.

<C-]>, <C-w>}, :tag /foo<Tab> and :cs f c bar are enough for my humble needs.

See eclim which has a very usable emacs interface which supports the same level of code navigation for java as Eclipse.

Eclim also supoprts C/C++ among others, though support for this is not yet implemented in emacs-eclim, but if you know Elisp then it is pretty trivial to implement, because for java all the necessary infrastructure is already there, so you only need to add the implementation for the c++ calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top