I have highlighted keywords and characters in bold and in different fg colours (with syn match). When I create an area highlight (e.g. between [ ] or ( )) the character and keyword highlighting is being overwritten. How can I preserve the foreground colour and other styling while only changing the background colour?

I want to achieve a similar result as in Visual Mode, that preserves most of the highlighting, but only changes the background. Also SpellCheck and Search highlighting works that way.

  • Welcome to Vi and Vim! What do you mean by an "area highlight"? Do you mean a syn region command? If that's the case, then the problem is possibly that Vim is only matching that region and not other keywords (or syn rules) inside it... You might need an explicit contains= to let it know it should match other rules inside the region. Can you give more details on which rules you're adding and example text you'd like to match? Please edit the question to add more details.
    – filbranden
    Jun 21, 2021 at 5:21
  • Please use edits for edits to the question (and it's easier if you do so from the same user account). Answers & solutions belong in answers.
    – D. Ben Knoble
    Jun 28, 2021 at 20:24

1 Answer 1


I solved my problem in understanding that the Search or SpellCheck functions are realized not via syn match or syn area, but by using the match function.

In my .vimrc, I now have:

highlight Dot term=standout cterm=bold ctermfg=Green
syn match Dot "\."

hi withinBrackets ctermbg=255 cterm=NONE ctermfg=NONE 
match withinBrackets /\[\_.\{-}\]/

If I have a string like "[whatever.]", the dot stays bold and green (like assigned from the syn match command), and additionally gets a greyish background (from the match command).

  • Maybe could you accept your answer using the v green button next to the arrow voting buttons. It will allow you question to rest :-) Mar 23, 2023 at 8:01

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.