3

Is there a plugin or way for me to alternate the background color for each line in vim?

E.g.

enter image description here


Previously I'd found vim-zebra but this looks really ugly:

enter image description here

I'd prefer the whole line to be colored, not just a part of it.

  • 4
    AFAIK this is impossible. – romainl Nov 4 '16 at 8:56
  • @romainl why? I doubt it, plugins like airline/powerline manage to color entire lines. – theonlygusti Nov 4 '16 at 9:01
  • 2
    No they don't. They colorize the status line and the tab line, which are designed to be colorized. Regular text lines are not designed to be colorized like that except for closed folds and the current line. – romainl Nov 4 '16 at 9:07
  • Note that you can change the colour of that vim-zebra plugin yourself with the :highlight command. The default is: hi Zebra ctermbg=green guibg=green – Martin Tournoij Nov 10 '16 at 18:20
  • 1
    Looks like your issue with vim-zebra is that your vim background is transparent, using that of the terminal emulator behind it, which means that vim-zebra's green is stopping short, only going as long as the text because that's effectively where 'vim stops'. – OJFord Mar 9 '17 at 17:39
4

It is possible using my plugin DynamicSigns. Quoting from the README:

2.7 Alternating colors

You can also set up the plugin to color the lines in your buffer in alternating colors. To do so, set the g:Signs_Alternate variable in your |.vimrc| like this:

:let g:Signs_Alternate = 1

This will display each even line nummer in one color and each odd line number in a different color.

Run :UpdateSigns or :Signs to update displaying the signs in your buffer.

  • I was trying to come up with a solution but couldn't find a clever way to define my syntax group. In your plugin I've found where you define the highlighting of the LineOdd and LineEven groups but I couldn't find where you define theses groups patterns (with a syntax match or similar function) would you mind pointing me out to this place? – statox Nov 4 '16 at 10:04
  • @statox, if you want to color the whole line even further than its contents, you need to use signs. Therefore, there is no syntax rule involed in that plugin but it uses only signs. – Christian Brabandt Nov 4 '16 at 10:06
  • @ChristianBrabandt Oh I see, I'm not familiar with the signs I'll study your code to understand it better :-) – statox Nov 4 '16 at 10:07
  • @ChristianBrabandt Okay. It was this part that can be interpreted wrongly, then: "This will display each even line nummer in one color and each odd line number in a different color." Maybe it could be changed to something like: "This will display each evenly numbered line in one color..."? – Rich Nov 4 '16 at 10:08
  • Can I make it alternate the gutter too? SignColumn? – theonlygusti Nov 4 '16 at 18:02

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.