Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lookup a specific kind of tag in Vim

Tags:

vim

ctags

So here's my problem. I've gotten exuberant ctags working with Vim, and it works great, most of the time. One thing that still irks me though is whenever I try to search for a function that is named the same as some variable name. I sometimes get the right tag on the first try, sometimes not. Then after I pull up the list of alternate tags with :tselect, it comes up with a list of tags for both function definitions or variable definitions/assignments. (I'm in PHP so definitions and assignments are syntactically indistinguishable).

However, I notice that there's a column labeled 'kind' that has a value of 'f' or 'v', for function and variable, respectively. I can't seem to find a whole lot of information about this field, it seems like it may not be exactly standardized or widely used. My question is: can you filter tag results in Vim by "kind"?

Ideally, the default would be to search the whole tags file, but by specifying some extra flag, you could search a specific ('f' or 'v') kind only.

This is such a small problem for me as it doesn't come up THAT often, but sometimes it's the small problems that really annoy you.

like image 245
Jonathan Avatar asked Oct 28 '11 17:10

Jonathan


People also ask

How do I set tags in Vim?

Select tag from tag list. You can select a particular tag from the tag list after opening the file in the vim editor by using ctags command. Open any source code in vim editor and type ':tselect' to find out the list of tag list of current source code. Here, the same file, abs_num.py is used to check this command.


1 Answers

You can certainly generate ctag files with any combination of php-kinds that you want (see the ouput of the command ctags --list-kinds.)

If you feel it's worth the effort you can make a vim function tagkind and bind it to a command. The tagkind function can overwrite the current tags vim variable to point at only the tag file with the kinds that you are interested in and call :tag. Optionally, it can store the previous version of the tags variable and restore it after this one call.

Unfortunately, I don't know of anyway other than this. Perhaps someone else would know.

like image 111
ldog Avatar answered Nov 20 '22 10:11

ldog