0

我可以使用 or 获取光标下的单词,我可以使用它打开文件并将其添加到 arg 列表中。例如,将光标放在 java 类名上,在第 45 行:

:arge +45 mydirhere/<cword>.java

但我不知道如何传递到标签机制中,所以它会返回文件名(和行号),可以传递给arge

所以我想我的问题具体是:“你怎么称呼标签机制?” 我期待类似的东西:

String getFileAndLineforTag(String tag)
4

2 回答 2

1

您可以使用该taglist()功能。从:help taglist()(在 Vim 7.1 中):

taglist({expr})                         *taglist()*
        Returns a list of tags matching the regular expression {expr}.
        Each list item is a dictionary with at least the following
        entries:
            name        Name of the tag.
            filename    Name of the file where the tag is
                    defined.  It is either relative to the
                    current directory or a full path.
            cmd     Ex command used to locate the tag in
                    the file.
            kind        Type of the tag.  The value for this
                    entry depends on the language specific
                    kind values.  Only available when
                    using a tags file generated by
                    Exuberant ctags or hdrtag.
            static      A file specific tag.  Refer to
                    |static-tag| for more information.
        More entries may be present, depending on the content of the
        tags file: access, implementation, inherits and signature.
        Refer to the ctags documentation for information about these
        fields.  For C code the fields "struct", "class" and "enum"
        may appear, they give the name of the entity the tag is
        contained in.

        The ex-command 'cmd' can be either an ex search pattern, a
        line number or a line number followed by a byte number.

        If there are no matching tags, then an empty list is returned.

        To get an exact tag match, the anchors '^' and '$' should be
        used in {expr}.  Refer to |tag-regexp| for more information
        about the tag search regular expression pattern.

        Refer to |'tags'| for information about how the tags file is
        located by Vim. Refer to |tags-file-format| for the format of
        the tags file generated by the different ctags tools.

当您定义自定义命令时,您可以指定 -complete=tag 或 -complete=tag_listfiles. 如果您需要做一些更详细的事情,您可以使用-complete=custom,{func}-complete=customlist,{func}。有关:help :command-completion更多信息,请参阅。

于 2009-06-26T20:43:44.947 回答
0

Here's some code to do it though not going to the right line, using Laurence Gonsalves's answer (thanks!)

:exe "arge " . taglist(expand("<cword>"))[0].filename

A confusing part was how to integrate the worlds of functions and ordinary commands, which is done with ("exe") and string concatention (".")

于 2009-06-26T21:40:00.263 回答