Reputation: 2213
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.
Upvotes: 9
Views: 2696
Reputation: 12793
fzf with fzf.vim has a :Tags
(for the whole project) and :BTags
for the current file option that generates ctags on the fly.
An issue raised on the plugin 'Skip tag kinds in :BTags and :Tags' gives the following code that you can use to only generated tags for a particular kind. I've modified the below so that it should only search for the PHP f
kind.
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'))], {})
Note as per my comment on the question, there is a potential Vim tagfinder.vim plugin via a blog post on Vim and Ctags: Finding Tag Definitions. But I haven't tried it.
Upvotes: 1
Reputation: 7050
I generate python ctags with --python-kinds=-i
to exclude tags for import statements (which are useless). Maybe you could generate with --php-kinds=-v
and drop a class of tags completely.
You can read :help tag-priority
. Apparently the "highest-priority" tag is chosen based on some hard-coded logic.
Upvotes: 5
Reputation: 12151
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.
Upvotes: 8