I have in my .vimrc:

hi SpellBad ctermfg=7 ctermbg=0* cterm=underline
hi Nonascii ctermbg=Black ctermfg=Red cterm=none
hi [...]

Some config files I need to look at contains so many unknown words that the highlighting defined in that highlighting group actually becomes a hindrance for visualization.

I am not looking for :syntax off followed by :syntax on. Obviously for any highlight group I could just issue :hi clear highlight-group. But then I'd be left with how to restore highlighting within the same session, without having to type in the exact line as it stands in the .vimrc file.

Any thoughts on how to selectively (exclusively) turn off and back on specific highlight groups, within a vim session, would be appreciated.

Just to be precise, I mean the question to be more general than just its specialization to the SpellBad highlight group. I have a few other highlight groups that I need to turn off and on from within a session.

  • 1
    Do you have set spell in your vimrc? If yes, remove it. If no, you can check who set spell by executing :verbose set spell?. – Ralf Apr 3 '19 at 9:45
  • 1
    Just use set spell! – klaus Apr 3 '19 at 10:39
  • @klaus, Ralf : tx but oops, wasn't thinking this morning. My question was a bit more general than the spell-checking example though. See my edit which clarifies it. – Cbhihe Apr 3 '19 at 17:24
  • 1
    I can't remember but there is a way you should be able to know what the highlight group of the word under cursor and then you can store the current highlight of that group in a temp global variable. Then use hi clear and when done, turn it back on with the stored variable. I can't do it myself now, I'm in phone. Sorry. – klaus Apr 3 '19 at 18:10

Turn of spell checking, as suggested in the comments:

:set nospell

With unimpaired: yos

| improve this answer | |
  • 1
    As suggested indeed. but my question was meant to be more general than the spell-checking example though. See my edit which clarifies it. – Cbhihe Apr 3 '19 at 17:24

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.