One of the first things you learn in vimtutor is to follow links in the vim help files with Ctrl-]. I'm interested in creating my own tags/linking system in arbitrary files. For the sake of this question, let's say I'm creating a sort of TODO list in markdown.

Suppose that we have the following minifile:

  1. Learn Vimscript the Hard Way    |hardway|

(some other things, maybe)

Complete Learn Vimscript the Hard Way
-------------------------------------  :hardway

(Some sort of details, etc.)

Then the goal would be to put the cursor on the first |hardway|, hit something akin to Ctrl-], and be transported to the :hardway tag located elsewhere. Ideally, this could even occur if :hardway was in a different file (but maybe the same directory).

I currently use a low-tech alternative. Instead of |hardway|, I would have something like |hardway.md|, so that I can gf on the "tag" and ge taken to the hardway.md file. While this is manageable, I feel like it should be possible (maybe even not hard) to create and maintain my own tag system on arbitrary filetypes.

  • Take a look at ‘:h write-help` – Cyber Oliveira Feb 4 '15 at 8:59
  • Sorry :h help-writing – Cyber Oliveira Feb 4 '15 at 9:00
  • @LeonardoConstantino Unless I'm mistaken, this would be akin to literally integrating my todo list into vim's help system. I'm not interested in typing :h hardway and being taken to my entry on hardway which is actually a helpfile. Or perhaps I'm misunderstanding your suggestion? Forgive me, I'm not entirely certain. – davidlowryduda Feb 4 '15 at 9:10

I've implemented something like this using Exuberant Ctags and a .ctags file in the directory (should also work with .ctags in the home directory).

You can read up on using Ctags with arbitrary regex, but the gist of it is that you'll be able to use that same Ctrl-] to go to these tags.

The contents of my .ctags:


Then run ctags.

ctags -R

And you should get a file called tags which has mappings for all markdown headers in the ### HEADER ### format.

See :help tags for more information about navigating tags (e.g. when there are multiple hits for a tag).


VIM's :find and gf are quite awesome, I use them all the time, they rely on the vim setting path and look for files in there. VIM also provides additional setting suffixesadd which is a list of suffixes find will try to add to the file names and look them up. eg.) set suffixesadd+='.md' to work with markdown files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.