Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create vim tags like the user manual

Tags:

vim

I want to make tags between .txt files in a way that's similar to the vim user manual.

I'm already aware of how to generate a tags file and I can link between my files. The only thing I want to figure out is how to make all of my tags a different color (like blue in the user manual) so they are easy to identify.

My best guess is that I'd have to customize syntax highlighting for a txt file, but I'm not sure how it would distinguish between tags and normal text.

like image 298
ackshooairy Avatar asked Mar 01 '26 12:03

ackshooairy


1 Answers

Extracting tags and their links is the one thing; you seem to have solved that part.

To recognize and highlight the tags, you need syntax rules. If your tags style follows the Vim help, tag definitions are surrounded by * characters, and tag links by | characters.

The following excerpt from $VIMRUNTIME/syntax/help.vim covers this:

syn match helpHyperTextJump "\\\@<!|[#-)!+-~]\+|" contains=helpBar
syn match helpHyperTextEntry    "\*[#-)!+-~]\+\*\s"he=e-1 contains=helpStar
syn match helpHyperTextEntry    "\*[#-)!+-~]\+\*$" contains=helpStar

hi def link helpHyperTextJump   Subtitle
hi def link helpHyperTextEntry  String

If you put that (optimally after replacing help... with txt...) into a custom ~/.vim/syntax/txt.vim syntax script, you can activate your syntax with :setf txt (or even automate this via a custom filetype detection).

like image 114
Ingo Karkat Avatar answered Mar 04 '26 01:03

Ingo Karkat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!