代码之家  ›  专栏  ›  技术社区  ›  13ren

在vim中,如何组合^]和arge,跟随标签并将其添加到arg列表中?

  •  0
  • 13ren  · 技术社区  · 16 年前

    我可以用或在光标下得到这个词,我可以用它打开一个文件并将其添加到arg列表中。例如,在一个Java类名上使用光标,在第45行:

    :arge +45 mydirhere/<cword>.java
    

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

    所以我想我的问题是:“你怎么称呼标签机制?”我在等类似的事情:

    String getFileAndLineforTag(String tag)
    
    2 回复  |  直到 16 年前
        1
  •  1
  •   Laurence Gonsalves    16 年前

    你可以使用 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 更多信息。

        2
  •  0
  •   13ren    16 年前

    这里有一些代码可以做到这一点,尽管不走正确的路线,使用劳伦斯·冈萨尔维斯的答案(谢谢!)

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

    一个令人困惑的部分是如何整合函数和普通命令的世界,这是通过 exe “)和字符串连接(” . “”