在 Vim 中查找特定类型的标签

发布于 2024-12-12 15:27:21 字数 434 浏览 5 评论 0原文

所以这是我的问题。我在 Vim 中使用了丰富的 ctags,而且大多数时候它都工作得很好。但仍然让我烦恼的一件事是,每当我尝试搜索与某些变量名称相同的函数时。有时我第一次尝试就得到了正确的标签,有时则不然。然后,在我使用 :tselect 拉出备用标签列表后,它会显示函数定义或变量定义/赋值的标签列表。 (我使用的是 PHP,所以定义和赋值在语法上是无法区分的)。

但是,我注意到有一个标记为“kind”的列,其值分别为“f”或“v”,分别表示函数和变量。我似乎无法找到有关该领域的大量信息,似乎它可能没有完全标准化或广泛使用。我的问题是:你能在 Vim 中按“kind”过滤标签结果吗?

理想情况下,默认情况是搜索整个标签文件,但通过指定一些额外的标志,您可以仅搜索特定的(“f”或“v”)类型。

这对我来说是一个小问题,因为它并不经常出现,但有时正是这些小问题真正让你烦恼。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风来 2024-12-19 15:27:21

您当然可以使用您想要的 php-kinds 的任意组合生成 ctag 文件(请参阅命令 ctags --list-kinds 的输出。)

如果您觉得值得付出努力,您可以制作一个 vim函数 tagkind 并将其绑定到命令。 tagkind 函数可以覆盖当前 tags vim 变量,以仅指向您感兴趣的类型的标记文件并调用 :tag。 或者,它可以存储 tags 变量的先前版本,并在本次调用后恢复它。

不幸的是,除此之外我不知道还有什么。也许其他人会知道。

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.

浮生未歇 2024-12-19 15:27:21

我使用 --python-kinds=-i 生成 python ctags 以排除 import 语句的标签(这是无用的)。也许您可以使用 --php-kinds=-v 生成并完全删除一类标签。

您可以阅读:help tag-priority。显然,“最高优先级”标签是根据一些硬编码逻辑选择的。

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.

顾忌 2024-12-19 15:27:21

fzf 与 fzf.vim 有一个 :Tags (对于整个project) 和 :BTags 用于动态生成 ctags 的当前文件选项。

插件提出的问题 '跳过 :BTags 和 :Tags 中的标签类型 ' 给出了以下代码,您可以使用它来仅生成特定类型的标签。我修改了下面的内容,以便它只搜索 PHP 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'))], {})

请注意,根据我对问题的评论,有一个潜在的 Vim tagfinder.vim< /a> 插件,通过 Vim 和 Ctags:查找标签定义。但我没试过。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文