4

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.

7
  • 4
    AFAIK this is impossible.
    – romainl
    Commented Nov 4, 2016 at 8:56
  • @romainl why? I doubt it, plugins like airline/powerline manage to color entire lines.
    – user9024
    Commented Nov 4, 2016 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
    Commented Nov 4, 2016 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 Commented Nov 10, 2016 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
    Commented Mar 9, 2017 at 17:39

1 Answer 1

5

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.

8
  • 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
    Commented Nov 4, 2016 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. Commented Nov 4, 2016 at 10:06
  • @ChristianBrabandt Oh I see, I'm not familiar with the signs I'll study your code to understand it better :-)
    – statox
    Commented Nov 4, 2016 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
    Commented Nov 4, 2016 at 10:08
  • Can I make it alternate the gutter too? SignColumn?
    – user9024
    Commented Nov 4, 2016 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.