I can get the word under the cursor with or , and I can use that to open a file and add it to the arg list. For example, with the cursor over a java class name, at line 45:
我可以用光标在光标下得到这个词,我可以用它来打开一个文件并将它添加到arg列表中。例如,将光标放在java类名上,在第45行:
:arge +45 mydirhere/<cword>.java
But I don't know how to pass into the the tag mechanism, so it will return the file name (and line number), that can be passed to arge
但我不知道如何传入标记机制,因此它将返回文件名(和行号),可以传递给arge
So I guess my question is specifically: "how do you call the tag mechanism?" I'm expecting something like:
所以我想我的问题是:“你怎么称呼标签机制?”我期待的是:
String getFileAndLineforTag(String tag)
2 个解决方案
#1
You can use the taglist()
function. From :help taglist()
(in Vim 7.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.
When you define a custom command you can specify -complete=tag or -complete=tag_listfiles
. If you need to do something more elaborate you can use -complete=custom,{func}
or -complete=customlist,{func}
. See :help :command-completion
for more on this.
定义自定义命令时,可以指定-complete = tag或-complete = tag_listfiles。如果您需要做更精细的事情,可以使用-complete = custom,{func}或-complete = customlist,{func}。有关详细信息,请参阅:help:command-completion。
#2
Here's some code to do it though not going to the right line, using Laurence Gonsalves's answer (thanks!)
使用Laurence Gonsalves的回答(谢谢!)这里有一些代码可以做到这一点虽然没有走向正确的路线
: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 (".
")
一个令人困惑的部分是如何整合函数和普通命令的世界,这是用(“exe”)和字符串连接(“。”)完成的。
#1
You can use the taglist()
function. From :help taglist()
(in Vim 7.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.
When you define a custom command you can specify -complete=tag or -complete=tag_listfiles
. If you need to do something more elaborate you can use -complete=custom,{func}
or -complete=customlist,{func}
. See :help :command-completion
for more on this.
定义自定义命令时,可以指定-complete = tag或-complete = tag_listfiles。如果您需要做更精细的事情,可以使用-complete = custom,{func}或-complete = customlist,{func}。有关详细信息,请参阅:help:command-completion。
#2
Here's some code to do it though not going to the right line, using Laurence Gonsalves's answer (thanks!)
使用Laurence Gonsalves的回答(谢谢!)这里有一些代码可以做到这一点虽然没有走向正确的路线
: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 (".
")
一个令人困惑的部分是如何整合函数和普通命令的世界,这是用(“exe”)和字符串连接(“。”)完成的。