Wikia

Vim Tips Wiki

Changes: Follow Help Tags Using Ctags

Edit

Back to page

(Standard formatting.)
(minor)
Line 1: Line 1:
It might be a nice idea to use helptags to jump around non-help files:
+
It might be nice to use helptags to jump around non-help files:
 
<pre>
 
<pre>
 
// my_program.c
 
// my_program.c
Line 17: Line 17:
 
Unfortunately <code>:helptags</code> only runs on <code>.txt</code> files. Two workarounds are:
 
Unfortunately <code>:helptags</code> only runs on <code>.txt</code> files. Two workarounds are:
   
*Create symlinks to txt files <code>~/.vim/docs</code>
+
*Create symlinks to txt files in <code>~/.vim/docs</code>
 
::[[Add your note files to Vim help]]
 
::[[Add your note files to Vim help]]
   

Revision as of 04:50, January 21, 2013

It might be nice to use helptags to jump around non-help files:

// my_program.c
...

// Important code! See |somewhere_else|
...

// *somewhere_else*
...

Pressing Ctrl-] should follow the |tag_reference| to the *tag_location* just like it does when browsing Vim's help.

The problem

Unfortunately :helptags only runs on .txt files. Two workarounds are:

  • Create symlinks to txt files in ~/.vim/docs
Add your note files to Vim help
  • Set filetype=help and use an external program to generate the tags
Keep a to-do memo file with links as in Vim help

Solution with Ctags

But if you are already using exuberant-ctags or taglist.vim, we can just create a new tag type "htag".

This must be done once for each file-type we want it to work on. Here is what I did for .java files:

Add to ~/.ctags:

--regex-java=/\*([A-Za-z0-9_\-]*)\*/\1/h,htag/

After regenerating the tags, Ctrl-] should now work within that project.

If you use the taglist plugin and you want to see these tags listed, add to ~/.vimrc

" Defaults from taglist.vim /_java_ with our h:htag type added.
let tlist_java_settings = 'java;p:package;c:class;i:interface;' .
                             \ 'f:field;m:method;h:htag'

Drawbacks

The simple pattern given above will be too general in many languages, for example it would find tags in: x = y*4*foo*bar . We could ask it to look for a whitespace either before or after it.

The words you use for your new htags should be unique, or will overlap with existing tags for functions, etc. I suggest using a different naming convention. E.g. in Java use non-camelcase with '_'s.

Tags will not jump directly into Vim help, unless you include help files in your ctags regeneration.

It would be nice to enable it for all filetypes automatically, rather than an an entry (or two) for every filetype we use.

Comments

Around Wikia's network

Random Wiki