Currently when working with vim's spellcheck a word is highlighted a certain color based on the type of error it is. Instead of highlighting the erroneous word I'd like it to be underlined with the highlighted color. I'm aware it's possible underline a certain highlight group with cterm=underline
, and I can change to foreground color with the ctermfg
option, but that changes the color of the word and underline whereas I just want the underline to be a different color.
1 Answer
Since Vim 8.2.0863 (May 2020) this can be done with ctermul
if your terminal supports it:
:hi SpellBad cterm=underline ctermul=blue
Also see the PR; this should be supported on VTE-based terminals, KiTTY, and perhaps some more. You can check if underline_rgb
is present in terminalprops()
(which was added a few patchlevels later, in 8.2.0970). Don't forget to set the correct TERM
value, otherwise it won't work (e.g. xterm-kitty
).
If you're using an older version or a terminal that doesn't support this then you're out of luck. Vim doesn't directly "draw" anything, it just sends text interspersed with escape codes for colouring, positioning, etc. and it's up to the terminal to interpret that.
Neovim doesn't support this at the time of writing; you can search the Neovim repo to see if it's supported if you're reading this a few years after posted.
In gvim you can do this with guisp
, which is used for both strikethrough and undercurl (but not underline):
:hi SpellBad gui=underline guisp=blue
This value is also used in the terminal if you enable termguicolors
and the terminal supports ctermul
.
-
I've updated my vim config file and everything seems to work as expected, including mixing foreground and underline colors (eg red underline and blue fg) thanks for the update! Just a note to those using neovim, as of 0.4.4
ctermul=<color>
doesn't work. Commented Feb 2, 2021 at 18:49
undercurl
andstrikethrough
using theguisp
attribute, and that is only possible in the gui