Code navigation in vim and emacs
Asked Answered
K

4

5

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?

Kahn answered 18/11, 2012 at 13:32 Comment(2)
When you downvote or vote for closure as not constructive, please, explain why did you do this? Personally, I don't think that the questions of how to do code navigation in vim and emacs is not constructive.Kahn
note that if you want to code in Java (and Scala too I think) from vim/emacs you can run Eclipse in headless mode (or in regular mode) while acting as a "server" and you can then use a vim client (eclim) or an emacs client (emacs-eclim) to get precisely the Eclipse code-completion / code navigation feature right from vim / emacs. eclim.org has screenshots / explanation.Wacky
H
5

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

Holzer answered 18/11, 2012 at 13:43 Comment(0)
E
6

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))))
Establishment answered 18/11, 2012 at 13:56 Comment(1)
Yes, Semantic also could be good source of information for navigation.Holzer
H
5

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

Holzer answered 18/11, 2012 at 13:43 Comment(0)
M
5

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.

Mella answered 18/11, 2012 at 14:15 Comment(0)
T
3

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.

Thomasina answered 19/11, 2012 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.