morhetz / gruvbox

Retro groove color scheme for Vim
13.62k stars 1.1k forks source link

Can't define color palette solely in Xresources with g:gruvbox_termcolors = 16 #130

Open danijar opened 8 years ago

danijar commented 8 years ago

I would like to have Xresources as the single place to define my system-wide color palette and have Vim use that by setting let g:gruvbox_termcolors = 16. However:

  1. Currently I have to specify set background=dark or set background=light in my Vim configuration, depending on the Xresources color scheme. Otherwise, the cursor line has the opposite color.
  2. The Vim background color does not perfectly match the background color in Xresources, which is what I would assume when using let g:gruvbox_termcolors = 16.

So I can't just change the Xresources colors to change my color scheme, but also have to edit the Vim configuration. Is there a way around these two issues?

morhetz commented 8 years ago

@danijar That's really nice feature to have which I've been thinking about recently too. I'll try to make a test branch for that.

danijar commented 8 years ago

Thanks. For the background color, gruvbox seems to use color0 rather than background from Xresources. For Vim to have the same background color as my terminal, I have to set both to the same value. But then black text becomes invisible.

morhetz commented 8 years ago

Well, actually it shouldn't But I got to check this

danijar commented 7 years ago

@morhetz how's this going? I'd really like this to happen, any way I can help?

rbong commented 5 years ago

For anyone still curious about this, Vim automatically sets background based on your terminal background color on startup if you haven't already set it, so you should only be able to set colors using just your .Xresources (save the background issue). However gruvbox does set the value of background so this will not currently work: source

rbong commented 5 years ago

Sorry for the double post, I've been looking into the other issue. Unfortunately it looks like the color0/background confusion is more difficult to solve.

Vim can only get the colors 0-15 through 16 color terminal codes. The 'fg' and 'bg' colors are based on the Normal highlight group and you can't just set NONE for foreground and use fg and bg or clear Normal.

Notice that the terminal has colors 0-15 which makes 16 colors, the full 16 color palette, not including foreground and background. Foreground and background in a real 16 color terminal would just be set to 0 (black) or 15 (white). So there is not a color code specifically for the color you set to your foreground or background color.

You would normally be expected to set Normal to the desired 16 color, 256 color, or hex color code depending on how many colors your terminal supports corresponding to your shell's configured foreground and background if you want them to match.

See :help ctermfg, and the link posted above (notice 0 is used for bg0). For proof try :hi clear, :hi Normal ctermfg=NONE ctermbg=NONE, :hi Visual ctermbg=bg. You will get a BG unknown error even if v:termrbgresp and $COLORFGBG are set.

You will have to set color0 to the background color if you want gruvbox to have the correct background. Perhaps gruvbox-contrib could contain alternative 16 color versions for Xresources files and terminal configurations. Looks like all of the gruvbox terminal config files are supposed to have matching foreground/background/color0/color15, but some don't. Some use a removed color or use light/hard background variations without any indication. If your colors look off, check your color0/color15/foreground/background against the official palette.