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.

  • I don't think this is currently possible. It looks like one can define the color attribute only for undercurl and strikethrough using the guisp attribute, and that is only possible in the gui May 8 '19 at 5:53

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. Feb 2 at 18:49

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.