tags:

views:

100

answers:

2

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:

: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

So I guess my question is specifically: "how do you call the tag mechanism?" I'm expecting something like:

String getFileAndLineforTag(String tag)
+1  A: 

You can use the taglist() function. From :help taglist() (in 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.

Laurence Gonsalves
exe "arge " . taglist(expand("<cword>"))[0].filename " thanks!
13ren
A: 

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 (".")

13ren