0

If I define a syntax highlighting region (or a match or keyword, for that matter), is it possible to specify or alter the background color of anything in that region, including things contained in it?

What I had hoped would work (but doesn't, of course) is something like (in ~/.vim/after/syntax/sh.vim)

if exists('b:current_syntax')
  let s:current_syntax = b:current_syntax
  unlet b:current_syntax
endif
syntax include @AwkSyntax syntax/awk.vim
if exists('s:current_syntax')
  let b:current_syntax = s:current_syntax
  unlet s:current_syntax
endif
syntax region AwkSglQuotes matchgroup=shQuote
\       start=#\(\<g\=awk\(\s\+[^']\+\)*\s\+\)\@<='#
\       end=#'# contains=AwkScript keepend containedin=shDo
syntax region AwkScript start=#[^']# end=#.\@=# contained
\       matchgroup=SpecialComment contained contains=@AwkSyntax
\       containedin=AwkSglQuotes
highlight AwkScript guibg=#EEEEEE

and then be able to type something like

[shell script with various commands]
BEGIN {a=0}
/cost/ {print $1}
END {print a}
' < $1

and have the AWK portion of the shell script highlighted with AWK syntax and the background of that region be light gray rather than white, to set it off.

That doesn't work (only the non-AWK-highlighted parts are affected), and there doesn't seem to be any way to "add" to the background color.

Is what I'm proposing possible in VIM?

1 Answer 1

1

The resulting highlight for each position in text is set according to the most deeply nested syntax match at that position. If such match lacks, say, background attribute then it's taken from Normal group.

Hence, every "final" match highlight must be changed independently. And so the answer is no, you can't. At least, not by syntax matching mechanism.

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.