The excellent Scriptease plugin by Tim Pope has a key binding zS
that prints the names of all the syntax highlighting groups under the cursor. The implementation is here; it uses synstack()
to get the list of highlight groups active at the current cursor position, and then map()
+ synIDattr()
to get the name of each, something like this:
let l:syn_ids = synstack(row('.'), col('.'))
let l:syn_names = map(syn_ids, {i,s -> hlIDattr(s, 'name')})
However, it doesn’t appear to work with highlight groups set by nvim_buf_add_highlight
, making it useless for debugging things like LSP semantic tokens and Tree Sitter highlighting. You can test this easily on a plain text file: if you nvim_buf_add_highlight()
, you should see the color of the highlighted text change according to whatever you set, but the zS
command over the highlighted text will not emit any output.
Specifically, the issue seems to be that synstack()
is entirely unaware of these extra extmarks-based (?) syntax highlighting groups. Is there some way to make it aware of them? If not, what is the equivalent functionality?