2009-06-26 8 views
0

Je peux obtenir le mot sous le curseur avec ou, et je peux l'utiliser pour ouvrir un fichier et l'ajouter à la liste d'arguments. Par exemple, avec le curseur sur un nom de classe java, à la ligne 45:dans vim, comment combiner ^] et arge, suivre un tag et l'ajouter à la liste arg?

:arge +45 mydirhere/<cword>.java 

Mais je ne sais pas comment passer dans le mécanisme de l'étiquette, il retourne le nom du fichier (et le numéro de ligne) , qui peut être passé à arge

Donc je suppose que ma question est spécifiquement: "comment appelez-vous le mécanisme d'étiquette?" Je me attends quelque chose comme:

String getFileAndLineforTag(String tag) 

Répondre

1

Vous pouvez utiliser la fonction taglist(). De :help taglist() (dans 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. 

Lorsque vous définissez une commande personnalisée, vous pouvez spécifier -complete = balise ou -complete=tag_listfiles. Si vous avez besoin de faire quelque chose de plus élaboré, vous pouvez utiliser -complete=custom,{func} ou -complete=customlist,{func}. Voir :help :command-completion pour plus à ce sujet.

+0

exe ​​"arge". taglist (expand ("")) [0] .filename "merci! – 13ren

0

est ici un code pour le faire mais ne va pas à la ligne droite, en utilisant la réponse de Laurence Gonsalves (merci!)

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

Une partie déroutante est comment intégrer les mondes des fonctions et des commandes ordinaires, ce qui est fait avec ("exe") et chaîne concatention (".")