4

synID() lets you get the syntax ID associated with a particular character at a particular line and column. This syntax ID is useful for querying other aspects of the syntax highlighting group (such as the name, colors, et cetera).

I've written a plugin that uses synID to let you interactively tweak the color of specific groups. I would like to support editing groups that don't ever appear in the document text (the cursor can never be over those, generally). The most reasonable way to do this would require me to look up a syntax ID based on the group's name.

Is there a built-in function to look up this mapping? Or do I need to build a look-up table myself?

  • Interesting plugin; I hope you are aware of the ColorSel plugin, which also implements a (generic) color selector. – Ingo Karkat May 14 '15 at 19:54
  • Not seen that one, but I know there's quite a few. Thanks for pointing it out. Mostly I write these for my own edification, I find that they teach me interesting things about vim. – Josh May 14 '15 at 19:57
4

You're looking for hlID(), and the odd hl-prefix probably made you not find it.

Example

:echo hlID("Comment")
46
  • Right after I committed a solution using a gross loop to scan manually. :D Thanks! – Josh May 14 '15 at 19:56

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.