How do I get the highlighting group of a text when the group is defined by the command :spell
?
For example when a word is misspelled I want to get the highlighting group SpellBad
.
We have a question on this site about how to get the highlighting group of a text in a buffer, the answer recommends to use the following command:
:echo synIDattr(synID(line("."), col("."), 1), "name")
and I also have another command using synstack
:
:synstack(line('.'), col('.'))
However both of these commands work pretty well for all of the highlighting groups others than the ones defined by :spell
(i.e. SpellBad
, SpellCap
, SpellRare
and SpellLocal
).
The only reference of this bug that I can find is this SO comment. Am I missing something or does anyone have a workaround?
:match
ormatchadd*()
expand('<cword>')->spellbadword()
to detect whether the word under the cursor is wrongly spelled, and if so, which type of spelling error it is (bad
,rare
,local
,caps
). But that doesn't tell you whether the word under the cursor is highlighted, because it depends on the syntax plugin which can specify where spell checking should be done (see:h spell-syntax
).term_start()
to open the file in another Vim instance in a terminal buffer, then you could useterm_dumpwrite()
to dump the terminal screen in another file. Finally, you would have to try to parse the screen dump to check whether the first character of the word is followed by some color code corresponding to one of the spelling error highlight group... For a start, see:h terminal-dumptest
, and this Vim test.