в vim, как объединить ^] и arge, чтобы следовать тегу, а также добавлять его в список аргументов?

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

  •  20-08-2019
  •  | 
  •  

Вопрос

Я могу поместить слово под курсор с помощью или , и я могу использовать это, чтобы открыть файл и добавить его в список аргументов.Например, с наведением курсора на имя класса Java в строке 45:

:arge +45 mydirhere/<cword>.java

Но я не знаю, как перейти в механизм тегов, поэтому он вернет имя файла (и номер строки), которое может быть передано arge

Поэтому я предполагаю, что мой вопрос конкретно:"как вы вызываете механизм тегов?" Я ожидаю чего-то вроде:

String getFileAndLineforTag(String tag)
Это было полезно?

Решение

Вы можете использовать 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 подробнее об этом читайте здесь.

Другие советы

Вот некоторый код, чтобы сделать это, хотя и не переходя к нужной строке, используя ответ Лоуренса Гонсалвеса (спасибо!)

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

Запутанная часть заключалась в том, как интегрировать мир функций и обычных команд, что делается с помощью ("exe") и объединение строк (".")

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top