13

I am using spell checker in vim, and I find one feature very annoying: errors are being highlighted with some weird color, which is nowhere to be found in gnome terminal settings:

highlighted error


I would like to change the highlight color to something else, so it doesn't obscure the wordd, without changing my global font color. How can I configure this?

1 Answer 1

13

The SpellBad highlighting group should allow you to configure the appearance of misspelled words.

Let's say you want them to be red on yellow background. Then you could add the following code somewhere in your vimrc file or in your colorscheme file (but in any case after the colorscheme has set up the SpellBad group, otherwise it would override your settings):

:highlight clear SpellBad
:highlight SpellBad ctermfg=009 ctermbg=011 guifg=#ff0000 guibg=#ffff00

The ctermfg, ctermbg arguments control the colors of the foreground and background colors in a terminal while guifg, guibg do the same for vim inside a gui.

For the terminal, the colors can be expressed with a name (red, yellow...) or a decimal code between 000 and 007 / 015 / 255 when it supports 8 / 16 / 256 colors. You can check how many colors it supports from vim with: echo &t_Co

For a gui, the colors can be expressed with a name or a code in hexadecimal.

Here's a chart which shows codes for some colors.

There are other highlighting groups (SpellCap, SpellLocal and SpellRare) which control the appearance of other kinds of words.

Note that setting the 'background' option causes your colorscheme to be reloaded. So if you have set background=dark somewhere in your vimrc, put the previous code which changes the SpellBad group after that line, otherwise the colorscheme will again override your settings.

For more information, see:

:help hl-SpellBad
4
  • 2
    Is it possible to only give an underline a different color? Such as hi SpellBad cterm=underline ctermfg=009 guifg=#ff0000
    – Tim Visée
    Commented Sep 6, 2017 at 9:39
  • The chart link is broken.
    – Adam Matan
    Commented Dec 31, 2017 at 8:18
  • Pointer to SpellCap, SpellLocal and SpellRare is very helpful, thx. Commented Oct 26, 2018 at 16:30
  • 1
    Updated link to a color chart commons.wikimedia.org/wiki/File:Xterm_256color_chart.svg
    – 3ocene
    Commented Jan 4, 2019 at 18:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.