no vim, como combinar ^] e arge, a seguir um tag e também adicioná-lo à lista arg?

StackOverflow https://stackoverflow.com/questions/1051096

  •  20-08-2019
  •  | 
  •  

Pergunta

Eu posso obter a palavra sob o cursor com ou, e posso usar isso para abrir um arquivo e adicioná-lo à lista de arg. Por exemplo, com o cursor sobre o nome da classe java, na linha 45:

:arge +45 mydirhere/<cword>.java

Mas eu não sei como passar no mecanismo da tag, então ele irá retornar o nome do arquivo (e número de linha), que pode ser passado para arge

Então eu acho que a minha pergunta é especificamente: "Como você chama o mecanismo de tag?" Eu estou esperando algo como:

String getFileAndLineforTag(String tag)
Foi útil?

Solução

Você pode usar a função taglist(). De :help taglist() (no 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.

Quando você define um comando personalizado pode especificar -completo = tag ou -complete=tag_listfiles. Se você precisa fazer algo mais elaborado, você pode usar -complete=custom,{func} ou -complete=customlist,{func}. Veja :help :command-completion para saber mais sobre isso.

Outras dicas

Aqui está algum código para fazê-lo, embora não indo para a linha direita, usando a resposta de Laurence Gonsalves (obrigado!)

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

A parte confusa era como integrar os mundos de funções e comandos comuns, o que é feito com ( "exe") e corda concatention ( ".")

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top