Is it possible to set alternating (one color for lines with odd line number and another for even line numbers) highlighting colors for each row in Vim?
This can do what you want with text background colors:
syn match Oddlines "^.*$" contains=ALL nextgroup=Evenlines skipnl
syn match Evenlines "^.*$" contains=ALL nextgroup=Oddlines skipnl
hi Oddlines ctermbg=yellow guibg=#FFFF99
hi Evenlines ctermbg=magenta guibg=#FFCCFF
Just add this to .vimrc
or the right file type .rc
you want.
Since this utilizes the syntax
functionality, it only applies to matchable typed text. I don't know if there's a way to alternate the background color of the empty "space" after text that hi Normal ctermgb=darkblue guibg=darkblue
does.
There's nothing built-in, so you would have to emulate that (and suffer from the consequences like slow performance, bad interference, etc.) A candidate would be :match
/ :call matchadd()
, because that is independent of syntax highlighting. Demo:
hi Alternate guibg=LightGrey guifg=NONE
execute 'match Alternate /\%(' . join(map(range(1,100), '"\\%" . v:val * 2 . "l"'), '\|') . '\)/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With