Sometimes when using vim I'd like to know why the syntax highlighting is coloring some text in a certain way. I'd like to be able to put my cursor on this text and enter some command to find out what syntax group it belongs to.
For example, I noticed that the first 50 characters of the first line in a gitcommit
buffer (ie: a git commit message) was being highlighted in an odd color. I'd like to know what syntax group is being used for these characters so I can adjust my (custom) color scheme.
The following command will output both the name of the syntax group, and the translated syntax group of the character the cursor is on:
:let s = synID(line('.'), col('.'), 1) | echo synIDattr(s, 'name') . ' -> ' . synIDattr(synIDtrans(s), 'name')
To make this more convenient it can be wrapped up in a custom command, function, or key binding.
How this works:
line('.')
and col('.')
return the current positionsynID(...)
returns a numeric syntax IDsynIDtrans(s)
translates s
by following highlight linkssynIDattr(s, 'name')
returns the name corresponding to the numeric syntax IDThis will output something like:
gitcommitSummary -> Statement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With