106

Right now, when I do :set spell in my Vim, I get spelling errors highlighted as if they are selected text. What I want is an MS-Word like underlining of spelling errors. I tried to lookup :help spell but could not find a clue. Any help is appreciated.

Ketan Maheshwari
  • 2,002
  • 3
  • 25
  • 31

3 Answers3

160

Spelling errors are highlighted using the SpellBad highlighting group. To get it highlighted as you want, you should put something like

hi clear SpellBad
hi SpellBad cterm=underline
" Set style for gVim
hi SpellBad gui=undercurl

after the last line that is altering the color scheme in your vimrc (it is either set background=(dark|light) or colorscheme {schemename}).

See also :h hl-SpellBad for names and descriptions of other Spell* highlight groups.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
ZyX
  • 52,536
  • 7
  • 114
  • 135
  • 3
    Beat me to it! It's also worth mentioning that `undercurl` ("squiggly" underlining similar to ms word) is the default in gvim, though obviously, there's no way to make a "squiggly" underline in a terminal. – Joe Kington May 15 '11 at 14:37
  • 30
    Could be useful to have a color change also, e.g., `:hi SpellBad cterm=underline ctermfg=red`. Or have it underlined _and_ bold: `:hi SpellBad cterm=underline,bold`. – Herbert Sitz May 15 '11 at 17:51
  • @yoda Replacing where? It is not impossible to make a X terminal that supports squiggly underlining, but I do not know about that feature in any of the terminals I use. And I guess this terminal will either have squiggly underlining instead of normal or will be unsupported by vim without manual patching. – ZyX May 18 '11 at 19:31
  • @ZyX: I don't know, was just wondering. All of mine show it as `----` too, but it just seemed logical that changing to squiggly should just involve replacing `-` with `~`, but I could be wrong there. – abcd May 18 '11 at 19:41
  • 2
    @yoda: I don't get where is `----` shown? Terminals don't use symbols for underlining (though you can always write your own that will), they just interpret particular escape sequence sent by vim as «start underlined region» and another sequence as «end underlined region» (or even «clear all styles»). What is actually shown is determined in code of the terminals, but I guess most of them just pass style information to font rendering library. Nothing here prevents terminals from supporting squiggly underlining, but font libraries don't use symbols for underlining. – ZyX May 18 '11 at 19:54
  • @LoremIpsum[about undercurl ~~~~](http://vimdoc.sourceforge.net/htmldoc/syntax.html#undercurl) – yuan Jun 27 '13 at 01:42
  • `hi clear SpellLocal` could also help, depending on the dictionary. – etham Jul 28 '21 at 11:11
3

The above needs to be typed everytime you set colorscheme. If you wish to avoid it, you should use autocmd.

See https://vi.stackexchange.com/questions/18295/how-to-set-a-colorscheme-that-still-shows-spelling-errors

Osamu Aoki
  • 41
  • 2
1

For a quick and dirty way to change the highlighting color if you have a colorscheme loaded, is to modify your colorscheme.

Running, :verbose highlight SpellBad showed me where the config file is for my theme. More like, it showed where the SpellBad directive was set. Your mileage may vary. Please see below output:

:verbose highlight SpellBad
SpellBad       xxx term=reverse ctermbg=9 gui=undercurl guisp=Red
        Last set from /usr/share/vim/vim81/colors/desert.vim line 17

I navigated to desert.vim and added, hi SpellBad term=reverse ctermbg=226 gui=undercurl guisp=Yellow1 and saved the file. (you'll need sudo to modify the file). Once I reopened vim and ran, :verbose highlight SpellBad the output was now:

:verbose highlight SpellBad
SpellBad       xxx term=reverse ctermbg=226 gui=undercurl guisp=Yellow1
        Last set from /usr/share/vim/vim81/colors/desert.vim line 35

My highlight color was changed! Note that if you change your colorscheme, you'll most likely have to change the highlight color in your selected colorscheme file.

Dharman
  • 30,962
  • 25
  • 85
  • 135
bennettnw2
  • 131
  • 2
  • 5