6

How to set a colorscheme that still shows spelling errors?

I am looking for two combined effects that I can acquire separately but not yet together.

  1. Set Colorscheme alone: OK. If I want highlights on spelling mistakes I can use a .vimrc file with this single line: set spell. So if I write a mwe file (mwe.vim) with a name in it as text content: John Morelock. Then the result is that vim recognizes John as a proper word, and does not highlight it, but then does properly highlight the last name. All OK up to here.

  2. Set Spelling alone: OK. As another task I would like to add a colorscheme, for example solarized. So I set colorscheme solarized as a single line in the .vimrc. All fine here. I open up the same previous file, and it shows the file with specific colorscheme. If I put both lines together, setting colors and spelling, all is OK here.

  3. Set Colorscheme and Spelling together: not always OK. The issue is that both previous procedures working together works under certain circumstances, such as with the mentioned colorscheme solarized, but not with another half of colors, at least in my specific case. I would like, for instance to use colorscheme adrian with spelling, but as soon as I use these two together, all of it stops working. To make adrianwork, the colorscheme line alone is not enough. Instead I have to add the line `set termguicolors', but this may be cancelling out my spelling to not show.

One hack is to eliminate schemecolors and fiddle with my terminal colors. Useful, but still my ideal solution would be to be able to choose colorschemes: adrian, matrix, onedark, or whatever. However, I would point out that many people seem to be asking questions about how to set coloring and highlights, so I would ask both a specific and a general question. I have browsed extensively, both in :h colorscheme and StackExchange. Where should one prioritize a search to begin solving this simple problem?

Where could I start looking for my specific problem? Both via web, and my pc.

How to set good practices for setting colors, spelling and in general?


Edit: I should add that I am not being able to use the adrian colorscheme with a single line invocation of setting colorscheme. To make it valid I have to add an extra line such as set termguicolors but this does not keep the spelling working properly.

3
  • Its a little confusing—are you trying to use different colorschemes? One for spelling and one for, well, everything else? At that point I would just highlight the spelling groups with whatever you want (after loading your colorscheme).
    – D. Ben Knoble
    Commented Dec 16, 2018 at 6:13
  • 2
    Additionally, we discourage more than one question per post in general, and your questions at the end are off topic and too broad, respectively, imo. Resource requests is not usually something StackExchange does; « general practices » simply is not a specific problem.
    – D. Ben Knoble
    Commented Dec 16, 2018 at 6:15
  • Nice @D.BenKnoble! I want to use colorschemes where the highlight is visible. For x reason, in my pc, half of the colorschemes don't show highlight. I was seeking for a Q&A that could be of help for people in the future when they want to define these two topics and learning from scratch. I am used to reading general practices in LaTeX SE, like everyday workflow, that's why I thought it would be OK to ask on this configuration. I can also remove the second question, I'll give it some thought.
    – nilon
    Commented Dec 17, 2018 at 12:19

2 Answers 2

8

I'm going to take a stab in the dark and suggest that your configuration is probably resulting in no highlighting.

You can check this with the command :verbose highlight SpellBad: if the xxx at the start of the line is not highlighted, then badly spelled words won't be highlighted, either.

If this is the problem, then spelling commands should still work correctly: you should still be able to jump to the next and previous error with ]s and [s, etc.

You can fix this by setting the highlighting yourself. You can simply add :highlight commands to your vimrc, but a better way is probably to use a ColorScheme autocommand. e.g.:

augroup my_colours
  autocmd!
  autocmd ColorScheme adrian hi SpellBad cterm=reverse
augroup END

Put this before the colorscheme line in your vimrc.

See :help :highlight and :help ColorScheme for more details.

10

Here is a bit more complete answer to address this annoyance:

" Force to use underline for spell check results
augroup SpellUnderline
  autocmd!
  autocmd ColorScheme *
    \ highlight SpellBad
    \   cterm=Underline
    \   ctermfg=NONE
    \   ctermbg=NONE
    \   term=Reverse
    \   gui=Undercurl
    \   guisp=Red
  autocmd ColorScheme *
    \ highlight SpellCap
    \   cterm=Underline
    \   ctermfg=NONE
    \   ctermbg=NONE
    \   term=Reverse
    \   gui=Undercurl
    \   guisp=Red
  autocmd ColorScheme *
    \ highlight SpellLocal
    \   cterm=Underline
    \   ctermfg=NONE
    \   ctermbg=NONE
    \   term=Reverse
    \   gui=Undercurl
    \   guisp=Red
  autocmd ColorScheme *
    \ highlight SpellRare
    \   cterm=Underline
    \   ctermfg=NONE
    \   ctermbg=NONE
    \   term=Reverse
    \   gui=Undercurl
    \   guisp=Red
  augroup END
  • Place this in your .vimrc
  • Add line colorscheme adrian after the above to start vim with adrian. This will set you up to use adrian and use underline for misssp[elled words.
  • You can also execute any color scheme from the vim command line, it will use underline for spell errors.
  • If you type at vim prompt as :colorscheme and space and CTRL-D, you get list of available color scheme which can be activated while using underline for spell. Trying many color scheme this way is the best way to get your favourite scheme.

Based on this, I made a simple plugin package: https://github.com/osamuaoki/vim-spell-under .

1
  • I fixed a no-display issue for Terminal-Vim on WSL with Windows Terminal ==> without the autocmd settings, I see no visual clues for wrongly spelled words when I am using Vim in the terminal. Now, things are fixed by displaying an underline marker below wrongly spelled words.
    – llinfeng
    Commented Oct 16, 2019 at 19:11

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.