How does vim choose a color that is not in the terminals color palette?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How does vim choose a color that is not in the terminals color palette?

S. Jacobi
I am using termite as my terminal emulator, which advertises 256 colors
support via terminfo. I only defined 20 colors: fg, fg_bold, bg, cursor
and the 16 colors in their normal and bright variants.
I do not use a vim colorscheme, just the terminal colors. In some shell
scripts I see colors that I have not defined and which are not affected
if I change my color palette. So my question is: How are those colors
determined and how can I change them?

How to reproduce:
1) set t_Co=256 in vimrc (if it is set to 16 those "new" colors do not
appear)
2) I set all 16 colors in my termite config file to #ff0000 (to
oberserve the changes)
3) Minimal shell script:
#/bin/bash
$testvar=1
cd dir
./command --help
4) $testvar is in cyan, --help is in some pinkish color

I haven't tested setting all 256 colors in my config file to red, if
this affects those two cases I found.

Kind regards

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does vim choose a color that is not in the terminals color palette?

Tony Mechelynck
On Thursday, June 15, 2017 at 2:35:39 AM UTC+2, S. Jacobi wrote:

> I am using termite as my terminal emulator, which advertises 256 colors
> support via terminfo. I only defined 20 colors: fg, fg_bold, bg, cursor
> and the 16 colors in their normal and bright variants.
> I do not use a vim colorscheme, just the terminal colors. In some shell
> scripts I see colors that I have not defined and which are not affected
> if I change my color palette. So my question is: How are those colors
> determined and how can I change them?
>
> How to reproduce:
> 1) set t_Co=256 in vimrc (if it is set to 16 those "new" colors do not
> appear)
> 2) I set all 16 colors in my termite config file to #ff0000 (to
> oberserve the changes)
> 3) Minimal shell script:
> #/bin/bash
> $testvar=1
> cd dir
> ./command --help
> 4) $testvar is in cyan, --help is in some pinkish color
>
> I haven't tested setting all 256 colors in my config file to red, if
> this affects those two cases I found.
>
> Kind regards
First, check that Vim knows that yout terminal allows 256 colors:

    :set t_Co?

The answer should be

      t_Co=256

If it isn't, and you know that your current console _does_ support 256 colors, you can set it. Even in your vimrc if you know how to identify that terminal (as opposed to a dumb 16-color text console) at startup, e.g. from its 'term' value.

Then, if you don't want to bother to identify where (at which ordinal) in the terminal palette a certain pink or green or whichever color is found, I recommend to use gui-like settings in the cterm. There are two ways to do that:

a) (easiest)
    if has('termguicolors')
        set termguicolors
    endif

b) to use guifg= guibg= in the cterm even with a gui-enabled Vim not compiled with +termguicolors, you could also take advantage of the CSApprox plugin, see
    http://vim.wikia.com/wiki/Using_GUI_color_settings_in_a_terminal#Solution_2:_the_CSApprox_plugin


Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does vim choose a color that is not in the terminals color palette?

S. Jacobi
On Wed, 14 Jun 2017 17:54:50 -0700 (PDT)
Tony Mechelynck <[hidden email]> wrote:

> On Thursday, June 15, 2017 at 2:35:39 AM UTC+2, S. Jacobi wrote:
> > I am using termite as my terminal emulator, which advertises 256
> > colors support via terminfo. I only defined 20 colors: fg, fg_bold,
> > bg, cursor and the 16 colors in their normal and bright variants.
> > I do not use a vim colorscheme, just the terminal colors. In some
> > shell scripts I see colors that I have not defined and which are
> > not affected if I change my color palette. So my question is: How
> > are those colors determined and how can I change them?
> >
> > How to reproduce:
> > 1) set t_Co=256 in vimrc (if it is set to 16 those "new" colors do
> > not appear)
> > 2) I set all 16 colors in my termite config file to #ff0000 (to
> > oberserve the changes)
> > 3) Minimal shell script:
> > #/bin/bash
> > $testvar=1
> > cd dir
> > ./command --help
> > 4) $testvar is in cyan, --help is in some pinkish color
> >
> > I haven't tested setting all 256 colors in my config file to red, if
> > this affects those two cases I found.
> >
> > Kind regards  
>
> First, check that Vim knows that yout terminal allows 256 colors:
>
>     :set t_Co?
>
> The answer should be
>
>       t_Co=256
>
> If it isn't, and you know that your current console _does_ support
> 256 colors, you can set it. Even in your vimrc if you know how to
> identify that terminal (as opposed to a dumb 16-color text console)
> at startup, e.g. from its 'term' value.
>
> Then, if you don't want to bother to identify where (at which
> ordinal) in the terminal palette a certain pink or green or whichever
> color is found, I recommend to use gui-like settings in the cterm.
> There are two ways to do that:
>
> a) (easiest)
>     if has('termguicolors')
>         set termguicolors
>     endif
>
> b) to use guifg= guibg= in the cterm even with a gui-enabled Vim not
> compiled with +termguicolors, you could also take advantage of the
> CSApprox plugin, see
> http://vim.wikia.com/wiki/Using_GUI_color_settings_in_a_terminal#Solution_2:_the_CSApprox_plugin
>
>
> Best regards,
> Tony.
>

Thanks for your answer. Me setting t_Co=256 in my vimrc was just
keeping this line for testing purposes. If t_Co is not set at all, it
is set automatically to 256 because this is what termite adertises via
terminfo. I can manually force it to 16 so the "extra" colors are not
used.
My vim was not compiled with the termguicolors feature, so I don't know
if b) applies here, too.
But I am actually interested in the internals. Is there a way to find
the color index without manually checking color16 to color 255? Or
even a comprehensive list of all uses of colorX with X > 15? No vim
color scheme is used.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does vim choose a color that is not in the terminals color palette?

Christian Brabandt
In reply to this post by S. Jacobi

On Mi, 14 Jun 2017, S. Jacobi wrote:

> I am using termite as my terminal emulator, which advertises 256 colors
> support via terminfo. I only defined 20 colors: fg, fg_bold, bg, cursor
> and the 16 colors in their normal and bright variants.
> I do not use a vim colorscheme, just the terminal colors. In some shell
> scripts I see colors that I have not defined and which are not affected
> if I change my color palette. So my question is: How are those colors
> determined and how can I change them?
>
> How to reproduce:
> 1) set t_Co=256 in vimrc (if it is set to 16 those "new" colors do not
> appear)
> 2) I set all 16 colors in my termite config file to #ff0000 (to
> oberserve the changes)
> 3) Minimal shell script:
> #/bin/bash
> $testvar=1
> cd dir
> ./command --help
> 4) $testvar is in cyan, --help is in some pinkish color
>
> I haven't tested setting all 256 colors in my config file to red, if
> this affects those two cases I found.

I think those are hard coded default values see syntax/syncolor.vim

Best,
Christian
--
F: Was ist orange und bohrt sich in die Wand?
A: Eine BOrange!

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How does vim choose a color that is not in the terminals color palette?

Tony Mechelynck
In reply to this post by S. Jacobi
On Thu, Jun 15, 2017 at 1:17 PM, S. Jacobi <[hidden email]> wrote:

> On Wed, 14 Jun 2017 17:54:50 -0700 (PDT)
> Tony Mechelynck <[hidden email]> wrote:
>
>> On Thursday, June 15, 2017 at 2:35:39 AM UTC+2, S. Jacobi wrote:
>> > I am using termite as my terminal emulator, which advertises 256
>> > colors support via terminfo. I only defined 20 colors: fg, fg_bold,
>> > bg, cursor and the 16 colors in their normal and bright variants.
>> > I do not use a vim colorscheme, just the terminal colors. In some
>> > shell scripts I see colors that I have not defined and which are
>> > not affected if I change my color palette. So my question is: How
>> > are those colors determined and how can I change them?
>> >
>> > How to reproduce:
>> > 1) set t_Co=256 in vimrc (if it is set to 16 those "new" colors do
>> > not appear)
>> > 2) I set all 16 colors in my termite config file to #ff0000 (to
>> > oberserve the changes)
>> > 3) Minimal shell script:
>> > #/bin/bash
>> > $testvar=1
>> > cd dir
>> > ./command --help
>> > 4) $testvar is in cyan, --help is in some pinkish color
>> >
>> > I haven't tested setting all 256 colors in my config file to red, if
>> > this affects those two cases I found.
>> >
>> > Kind regards
>>
>> First, check that Vim knows that yout terminal allows 256 colors:
>>
>>     :set t_Co?
>>
>> The answer should be
>>
>>       t_Co=256
>>
>> If it isn't, and you know that your current console _does_ support
>> 256 colors, you can set it. Even in your vimrc if you know how to
>> identify that terminal (as opposed to a dumb 16-color text console)
>> at startup, e.g. from its 'term' value.
>>
>> Then, if you don't want to bother to identify where (at which
>> ordinal) in the terminal palette a certain pink or green or whichever
>> color is found, I recommend to use gui-like settings in the cterm.
>> There are two ways to do that:
>>
>> a) (easiest)
>>     if has('termguicolors')
>>         set termguicolors
>>     endif
>>
>> b) to use guifg= guibg= in the cterm even with a gui-enabled Vim not
>> compiled with +termguicolors, you could also take advantage of the
>> CSApprox plugin, see
>> http://vim.wikia.com/wiki/Using_GUI_color_settings_in_a_terminal#Solution_2:_the_CSApprox_plugin
>>
>>
>> Best regards,
>> Tony.
>>
>
> Thanks for your answer. Me setting t_Co=256 in my vimrc was just
> keeping this line for testing purposes. If t_Co is not set at all, it
> is set automatically to 256 because this is what termite adertises via
> terminfo. I can manually force it to 16 so the "extra" colors are not
> used.
> My vim was not compiled with the termguicolors feature, so I don't know
> if b) applies here, too.

The CSApprox plugin was written before the +termguicolors feature was
even invented. It applies regardless of its presence, in any Vim
version which can remember GUI highlight settings while running in the
console. I tried to find out which Vim version this means but failed.
If when running Vim in a console and setting both (gui= guibg= guifg=
guisp= ) and (cterm= ctermfg= ctermbg= ) parts of the :highlight
command they are both remembered, then you should be all right.

> But I am actually interested in the internals. Is there a way to find
> the color index without manually checking color16 to color 255? Or
> even a comprehensive list of all uses of colorX with X > 15? No vim
> color scheme is used.

From the CSApprox plugin help:
[...]
Also, there are at least three different 256-color palettes in use.  Nearly
all terminals use an xterm-compatible palette, so most users need not concern
themselves with this, with only two exceptions:  Eterm uses a slightly
different palette, and older Konsole (pre KDE 2.2.0) used a third palette.
CSApprox has no reliable way to tell which palette your terminal uses, so it
makes some educated guesses:
[...]

There is also a "colortest" plugin, see ":help colortest.vim" — but by
default it will display the basic bg & fg colors by setting special
highlight groups to them. Vim cannot define anywhere near 16777216²,
or even 256², highlight groups at the same time so it is not possible
to get a list of all possible combinations displayed. IIUC the 256
colors are subdivided in 3 categories:
- Colors 0 to 0x0F are the colors used by 16-color terminals
- 216 (i.e. 6³) positions are used for the so-called "safe" colors,
i.e. those of the 16777216 for which the red, green and blue settings
are each (separately) a multiple of 0x33, namely one of {0x00, 0x33,
0x66, 0x99, 0xCC, 0xFF} for red, one of the same list for green and
one of the same list for blue.
- The rest (24 positions) are additional greyscale values.

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...