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?

2
  • Interesting plugin; I hope you are aware of the ColorSel plugin, which also implements a (generic) color selector. May 14, 2015 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.
    – user72
    May 14, 2015 at 19:57

1 Answer 1

4

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

Example

:echo hlID("Comment")
46
2
  • Right after I committed a solution using a gross loop to scan manually. :D Thanks!
    – user72
    May 14, 2015 at 19:56
  • Saved me from having to write that loop though, thank you!
    – SidOfc
    Mar 18, 2020 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.