I am using ":ta " to jump to a method.
For example i got two classes named A.java
and B.java
. They both have a foo()
method and B.java have another method called fooBar()
. Then i open A.java
and input :ta foo
then press TAB then i will got two completion : foo
and fooBar
. But what i want to jump now is just tag in current file, i don't like tag in other file to display.
Depending on how many times you call your methods a couple of *
may be enough.
Without using tags, gd
can be used to go to the local declaration of the method under your cursor. I tend to choose the most low-tech solution usually, so I would go with this one.
But ctags
is also able to generate tags for a single file only or for an arbitrary selection of files. It can be done in a few steps but it's definetely not as straightforward as what you are accustomed to do…
Create a file with the name(s) of the file(s) you want to scan. Let's say it's called
files.txt
and it's located at the root of your working directory.Generate your
tags
file using the-L <file>
argument:ctags -L files.txt
.
At this point you should have a tags
file containing only the tags present in the file(s) specified at step 1.
Generating different tags
files for the whole project and for single files may be useful, here. A short script generating a tags
file named after the current file and making it the sole tags
source may make the whole thing easier.
EDIT
Actually, TagList and TagBar don't generate tags
files. The output of the ctags <options>
command they run is used internally and parsed with all kinds of regexp to filter by scope or filename or whatever.
taglist
works. But i found that the generated tags file have a column called class, so i guess that may have some methods to search tags with specified class name. –
Photoreceptor tags
file tied to one file or you find a way to filter your large project's tags
file. –
Crack Unfortunately this cannot be done using ctags. Ctags does not respect context, it is a pure list of all possible "functions". Try to open a tag file with an editor (e.g. vim) and you will see it is just a list of "functions" (in case of Java they are "methods"). Example:
getDesc src/com/redhat/rhn/internal/doclet/Handler.java /^ public String getDesc() {$/;" m class:Handler
getDoc src/com/redhat/rhn/internal/doclet/ApiCall.java /^ public String getDoc() {$/;" m class:ApiCall
Vim just search the file "as is" without giving it any context - it just search for a "function". It is able to search for files, classes, methods, enums etc. Tags format is described in more detail here: http://ctags.sourceforge.net/FORMAT
In Vim you have few possibilities. There are several plugins that gives Vim some context sensitivity, but you cannot use tags for that. Vim itself has a feature called OmniComplete and there are few plugins dedicated for Java. Then you can use Ctrl-X Ctrl-O to start a completition. I recommend you to map this to a different key (maybe Ctrl-Space if you like). More info about Java OmniComplete plugins here:
Eclim (http://eclim.org/) is very comperhensive, but difficult to setup (you need to run Eclipse in the background). JDE script is easier and also robust (http://www.vim.org/scripts/script.php?script_id=1213). And please note IntelliJ IDEA Community Edition (free) also has a very nice Vim plugin that is free to use. But I understand you - Vim is Vim.
Good luck!
TagList
is just what i need. If i can search tag displayed by TagList
then this problem is solved. –
Photoreceptor Not exactly an answer to your question, but it seems like there's no way to do exactly what you need, so, i would recommend you the following: for your Java development in Vim, try eclim.
This tool helps you to use your favorite text editor Vim with power of an Eclipse (IDE).
I can't find analogue for tab-completion of :ta
, but i know a smart analogue for g]
: this is a command :JavaSearchContext
. You can map it to something.
For example, if you have two classes A
and B
, and you have method foo()
in each class, then g]
will ask you every time you want to jump to foo()
, but :JavaSearchContext
will always jump to the proper declaration of foo()
.
Of course, there are many other features.
© 2022 - 2024 — McMap. All rights reserved.