1

This was a nice little article that somewhat demystified vim colors to me.

I downloaded and installed the Base2Tone vim colorschemes, and set the following in my ~/.vimrc:

colorscheme Base2Tone_PoolDark
hi LineNr ctermfg=yellow ctermbg=NONE

I was mostly satisfied with the result in vim:
enter image description here

But I much prefer how it renders in gvim:
enter image description here

Is there some way I can get vim's colorscheme rendering more like gvim's?


Note: I mentioned the hi LineNr because I'm curious why the line numbers don't render yellow in gvim - but I don't necessarily want to clutter this post with too many incidental questions - I'm mostly interested in the background color rendering. To my eye, it looks like the text (foreground?) colors are a pretty reasonable match.


UPDATE:

Based on @filbranden's answer, I tried export TERM=xterm-true-color and restarting vim, and this looks like it's on the right track, but it's still a bit off -- it looks like it's filling spaces past EOL with black; does anyone recognize the issue, and what setting to change so there isn't that mismatched background color?
enter image description here

  • it looks like it's filling spaces past EOL with black Does it help if you write this in your vimrc set t_ut=? – user938271 May 15 at 5:19
  • @user938271 - Yes, everything past EOL and also TABs (not evident from the screenshot). So only the background of alpha-num-space is rendered with the purple. Tried adding set t_ut= , but didn't seem to have any effect; but thank you. – StoneThrow May 15 at 17:26
3

Highlight in gui or true color terminal with :h termguicolors is not affect by :h cterm, cterm is used for 8, 16, 256 color terminal. This command should change gui LineNr:

hi LineNr guifg=#ff0000 guibg=#000000

A quick look at the source, this colorscheme use only 16colors, it doesn't use ansi 16 colors, it works for gui, true color and 256color terminal.

If your terminal has truecolor, you can turn on termguicolors, it will use gui color to render terminal.

If your terminal is 256color, you must setup your 256 color palette, otherwise it will be degraded.

Change xterm-256color color palette

color palette is usually set by Operating System Command (OSC) characters, it's ESC] in xterm

ctlseqs.txt.gz
---------------------
Operating System Commands
...
OSC Ps ; Pt ST
...
            Ps = 4 ; c; spec -> Change Color Number c to the color spec-
          ified by spec.  This can be a name or RGB specification as per
          XParseColor.  Any number of c/spec pairs may be given.  The
          color numbers correspond to the ANSI colors 0-7, their bright
          versions 8-15, and if supported, the remainder of the 88-color
          or 256-color table.

It's a bit hard to read, it basically says you can change your 256 color palette by:

{OSC characters}4;{color index};{XParseColor color specification}{ST characters}

We already know OSC, color index is 0-255, ST is ESC\, You can find XParseColor specification in man xparsecolor:

...

COLOR NAMES
       An RGB Device specification is identified by the prefix ``rgb:'' and conforms to the follow‐
       ing syntax:

       rgb:<red>/<green>/<blue>

Put everything together:

printf "\033]4;235;rgb:30/30/30\033\\"

Above command will change color 235 to #303030

Different TERM use different escape sequece to change 256 color palette. This might only applied to xterm family terminal.

Popular colorscheme such as gruvbox will provide a shell script to help you setup your color palette.

| improve this answer | |
  • Not sure I'm applying your suggestion correctly: I understand the general concept: i.e. a 256-color terminal can display 256 colors at a time out of a total palette of however many colors. And that printf command is supposed to change color #235, which I think you determined is the background color used by the Base2Tone_PoolDark colorscheme. So I ran that command in my xterm-256color term, and restarted vim, and I see the background rendered in gray (just like the very first screenshot) instead of purple -- am I misunderstanding something? – StoneThrow May 15 at 17:53
  • I tried a different color: like I used google's online color picker, and tried to pick color #a175a0 by doing printf "\033]4;235;rgb:a1/75/a0\033\\" then restarting vim, but that also resulted in a gray background that looked the same as that very first screenshot. – StoneThrow May 15 at 17:57
  • 1
    @StoneThrow 235 is just a random color, I don't know if it's used in Base2Tone-PoolDark. You can check your colorscheme's source, you need to change all colors used by your colorcheme. – dedowsdi May 15 at 23:17
1

Is there some way I can get vim's colorscheme rendering more like gvim's?

Yes! As long as your terminal supports "true color," you can ask Vim to use the gvim color settings of the colorscheme by enabling the 'termguicolors' setting:

When on, uses highlight-guifg and highlight-guibg attributes in the terminal (thus using 24-bit color).

Requires a ISO-8613-3 compatible terminal. If setting this option does not work (produces a colorless UI) reading xterm-true-color might help.

Simply add this line to your vimrc:

set termguicolors

If that doesn't work, take a further look at the documentation to ensure your terminal supports this feature and is properly configured to use it.


Your terminal emulator, MobaXterm, is supposed to support "true color", so it should be possible to make it work.

If setting TERM=xterm-true-color is giving you trouble, then try to keep TERM=xterm-256color and set vim options t_8f and t_8b explicitly, as recommended in :help xterm-true-color:

let &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
let &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"

(And, if that doesn't work, try using semicolons instead of colons in those expressions.)

| improve this answer | |
  • Doing this gave me a B&W colorscheme. This is a little bit outside my expertise, but I tried to read up on your answer, so now I think this is because my Terminal (MobaXTerm, ssh session to a Linux box) is setting xterm-256color -- do you think that's why? Also, I didn't quite understand the quote "reading xterm-true-color might help" -- does that mean I should set $TERM to xterm-true-color instead of xterm-256color? – StoneThrow May 15 at 4:20
  • Ah! Getting close! I manually did export TERM=xterm-true-color, then re-ran vim, and now the background color where text is present looks the right color -- but it looks like TAB whitespace and anything past EOL is still black. – StoneThrow May 15 at 4:25
  • @StoneThrow Updated my answer with another suggestion you can try. – filbranden May 15 at 4:58
  • 1
    Some interesting results here: if I set xterm-256color and add those two lines (with semicolons instead of colons) and comment-out set termguicolors, the background is rendered a light gray (instead of purple). If I uncomment set termguicolors, then I get the mixed purple/black background rendering. If I set xterm-true-color, with termguicolors and those two lines, I get the mixed purple/black background, and without termguicolors, I get total B&W rendering. – StoneThrow May 15 at 17:22

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.