Search for a specific type of tag in Vim

So here is my problem. I get violent ctags working with Vim and it works great, most of the time. One thing that still annoys me is when I try to find a function that is called just like the name of a variable. Sometimes I get the correct tag on the first try, sometimes not. After I pulled out a list of alternative tags with :tselect , it contains a whole bunch of tags to define functions or definitions of variables / assignments. (I am in PHP, so the definitions and assignments are syntactically indistinguishable).

However, I notice that there is a column labeled "kind" that has a value of "f" or "v" for the function and variable, respectively. It seems that I can not find much information about this field, it seems that it can not be precisely standardized or widely used. My question is: can you filter the results of the tag in Vim "good"?

Ideally, by default it will search the entire tag file, but by specifying some additional flag, you can only search for a specific ('f' or 'v') view.

This is such a small problem for me, as it often does not occur, but sometimes these are small problems that really annoy you.

+4
source share
3 answers

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

If you think this is worth the effort, you can make a vim tagkind function and bind it to the command. The tagkind function can overwrite the current tag variable vim to point only to the tag file that interests you and call :tag. . If desired, he can save the previous version of the tags variable and restore it after this one call.

Unfortunately, I do not know anything but this. Perhaps someone else would know.

+4
source

I generate python ctags with --python-kinds=-i to exclude tags for import statements (which are useless). Perhaps you can generate with --php-kinds=-v and completely remove the tag class.

You can read :help tag-priority . Apparently, the "highest priority" tag is selected based on some hard-coded logic.

+5
source

fzf with fzf.vim has :Tags (for the whole project) and :BTags for the current file option, which generates ctags on the fly.

The problem raised in the Skip tags in: BTags and: Tags ' plugin gives the following code, which you can use only created tags for a specific type. I modified the following so that it can only search for PHP type f .

 command! BTagsEnhanced \ call fzf#vim#buffer_tags(<q-args>, [ \ printf('ctags -f - --sort=no --php-kinds=f --excmd=number --language-force=%s %s', &filetype, expand('%:S'))], {}) 

Please note that according to my comment on the question, there is a potential Vim tagfinder.vim plugin via the Vim and Ctags blog post : defining tag definitions . But I have not tried.

0
source

All Articles