Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search tags only in current file

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.

And i found tagslist does very good in this job. So if i can use the tag generated by taglist to search from, it will be very nice.
like image 996
Frank Cheng Avatar asked Dec 28 '11 13:12

Frank Cheng


1 Answers

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…

  1. 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.

  2. 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.

like image 89
romainl Avatar answered Sep 18 '22 07:09

romainl