如何更改 Vim 拼写检查中的突出显示样式?

现在,当我在我的 Vim 中执行 :set spell时,我会突出显示拼写错误,就好像它们是选中的文本一样。我想要的是一个像下划线的拼写错误的 MS-Word。我试图查找 :help spell,但找不到线索。感谢你的帮助。

33109 次浏览

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.

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

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.