I would like to use two different backgrounds colors bg1
and bg2
with:
bg1
for all text on a line (possibly nothing if line is empty) up to the end-of-line,bg2
for the empty area after the end-of-line,- while keeping
hlsearch
working, - and syntax highlighting working.
For example, if displaying <empty_area>
as _
's starting with #
on a 16-character-wide window, with "text"
as the search pattern and a syntax recongizing if
, it would look like:
if "text"#______
#_______________
indented#___
with:
- anything but the trailing
_
's with a different background (here black foreground)... - ...than the trailing
_
's (here gray foreground), - except for
"text"
which should be highlighted as theSearch
group (here green foreground), - and
if
which has the syntax highlighting of the chosen language (here blue foreground).
I have tried this in my vimrc
:
hi Normal guibg=Gray75
hi Contents guibg=LightGray
match Contents /.\+.\@!/.
but then I lose the pattern match highlighting for hlsearch
, which is I guess superseded by the Contents
match.
Is there a proper way to achieve what I want: different backgrounds for text and empty area after EOL, with hlsearch
and syntax highlighting still working ?
PS: The NonText
group is not relevant, since it links to the empty area after the buffer, and not after each line.
:set list
. While it may not look quite as good, it was built exactly for this use case.EOL
does not fit to my eye, but allowed me to find my solution. Thanks @d-ben-noble and @friedrich.lcs
(listchars
) variable was not judiciously set on the file I tried:set list
with. In fact, withset lcs=tab:> ,trail:-,extends:>,precedes:<,nbsp:+
, I get a nice complement to the2match
solution... Thanks again.