8

I have been playing with color schemes for terminal VIM and have found something annoyingly frustrating that I have been unable to solve thus far.

I expect the 16 system colors to change. They are obviously configurable. For that reason, I attempted to use the 256-color palette to construct a VIM color scheme that would be the same regardless of the terminal's 16 (configurable) system color palette.

I used only colors from the 256 color palette for everything, including background. However, I noticed that if I open terminals with different background and text colors specified for the terminals, the VIM color schemes appear quite different in the two terminals.

I do not see similar behavior on Ubuntu even when the terminals have different background, foreground, AND system color palettes.

I will happily accept an answer that explains why this happens.

I will be ecstatic if someone can tell me a way around this beyond setting up a specific terminal for each set of color settings I want to use.

wrossmck
  • 369
  • 8
  • 21
toadjamb
  • 934
  • 1
  • 9
  • 14
  • 1
    Just to be clear, you are using `t_Co=256` and `TERM=xterm-256color` right? – Michael Berkowski Apr 01 '12 at 18:39
  • Yeah, that was taken care of LOOOONG ago. :) – toadjamb Apr 01 '12 at 18:58
  • it could be the auto-adjustment as described here: http://apple.stackexchange.com/questions/29487/is-it-possible-to-disable-terminals-automatic-tweaking-of-colors-in-lion –  Aug 04 '14 at 20:18
  • if it is the auto-adjustment, here is a hack around it: https://github.com/earwin/TruColor –  Aug 04 '14 at 21:03

6 Answers6

4

By default, ANSI terminals are 16 color devices and the Vim color schemes that work in gvim will not work properly in a terminal.

Some terminals are capable of 88 or 256 colors. You can tell Vim about this by setting t_Co. Of course, 256 colors is still less than full RGB that you have in gvim.

There is a package for vim called CSApprox developed by Matt Wozniski. It lets you use the gvim color schemes with approximate colors.

This is what I use myself.

CSApprox includes a documentation file which explains everything better than I can here.

URL: http://www.vim.org/scripts/script.php?script_id=2390

Good luck.

P.S. about your question However, I noticed that if I open terminals with different background and text colors specified for the terminals, the VIM color schemes appear quite different in the two terminals.

That sounds like the OSX terminal does not separate the color definition from the 256 color xterm palette; i.e. that by manipulating its settings you're messing with the palette or something like that.

Terminals should probably be keeping the 16 color user-configurable stuff separate from the 256 color palette.

Kaz
  • 55,781
  • 9
  • 100
  • 149
  • 1
    Another useful bit of information, about where ANSI extension for supporting more colors comes from: http://www.mudpedia.org/wiki/Xterm_256_colors – Kaz Apr 01 '12 at 18:49
  • I have been aware of CSApprox for a long time, but there are two issues with using it. One is that I only use terminal VIM and have no interest in GVim. The second is that I am very picky about my colors and would like to choose them very specifically. – toadjamb Apr 01 '12 at 18:56
  • `CSApprox` isn't for gvim. It's exactly for users who don't use gvim but terminals. It's just that gvim is the reference model for how color schemes are supposed to display. If you're picky about colors (I.e. want to choose every one of the 24 RGB bits) then I think you're out of luck doing it through Vim. You must edit your terminal's palette through its preferences mechanism. – Kaz Apr 01 '12 at 19:01
  • 1
    I am also able to loop through the colors and see them in the terminal and on the background color I specify so I can see what I'm getting for a given terminal color scheme. The colors are quite different. This is the problem. I had run across the mudpedia page before, which helped me with that. – toadjamb Apr 01 '12 at 19:04
  • I don't want to pick from every one of the 24 RGB bits. But I do want to know exactly which colors I'm using and tweak them. Using CSApprox, I don't know how much I have to change a color to get a different "shade". Using the index of the 256 color palette, I just change to a different index. The problem is that the colors indexed seem to change with the color scheme and I'm not sure why. I would venture to guess that I would see the same issue with CSApprox. At the end of the day it's indexing into the same palette I'm using. Most people just don't care enough to notice. – toadjamb Apr 01 '12 at 19:11
  • 1
    “Terminals should probably be keeping the 16 color user-configurable stuff separate from the 256 color palette.” They are separate. Lion Terminal lets you edit the ANSI colors, but the 256-color palette is fixed. – Chris Page Apr 06 '12 at 04:08
2

Terminal dynamically adjusts some color values to ensure a minimum amount of contrast with the background color. Perhaps that’s what you’re seeing.

Please attach a screenshot showing the two different color schemes. A good script for viewing the available colors is 256colors2.pl.

Chris Page
  • 18,263
  • 4
  • 39
  • 47
0

The 256 colour mode is still just an indexed palette, the same as the 8 and 16 colour modes. The application simply selects a colour by index from a palette, and it's up to the terminal to decide which colour that will actually be.

That two different terminals happen to pick the same colours for these indexes may just be the fact that within the 216-colour RGB cube there's 6 levels of each component, so the "obvious" natural way to assign those colours would be to pick each from the list (0, 0x33, 0x66, 0x99, 0xcc, 0xff). I'd imagine most terminals will do this, and therefore give the same colours at the same indices.

If two terminals differ it's simply an indication they're using some other method of selecting their actual colours.

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
  • The default 256 color table should be essentially the same on all terminal emulators. Exact color values may vary, but there’s a “standard” description of the default set of colors. Color calibration can also produce slight variations. – Chris Page Apr 06 '12 at 04:04
0

If you are using iTerm2 then you may need to change what type of terminal it is reporting.

In your iTerm2 Preferences > Profile > Terminal > Report Terminal Type, set to xterm-256color

Brett Y
  • 7,171
  • 1
  • 28
  • 42
0

In Terminal.app aka Apple Terminal, the colours will change if the background colour is not explicitly set as well.

So with your colour scheme you must set up the default background colour using the Normal colour group, e.g.:

hi Normal ctermfg=188 ctermbg=234

and then you should not see any further changes to colours.

Note: I have only noticed the foreground being affected presumably so that you do not miss any important output ;)

casr
  • 1,166
  • 2
  • 11
  • 17
0

Please, post screenshots so that we see what you see. It's hard to talk about colors without seeing them or comparing their numerical values.

Well, I'm still on 10.6.8 so I've never enjoyed Terminal.app's ability to display 256 colors.

But, AFAIK, its default 16 colors are not taken from the X11 palette. They are probably hardcoded somewhere and their values are user-configurable anyway. Because of that, I have no idea why changing the default Red value to anything would change the looks of your Vim colorscheme.

However, Terminal.app (like most other terminal emulators) allows you to change the values of Background, Text, Bold, Selection and Cursor. Depending on how your colorschemes are written some of these settings may override parts of your colorscheme, Background, most notably.

I've had my Terminal.app background matching my Vim colorscheme's background for a long while with great results. Well, at least for a 16 color terminal emulator.

romainl
  • 186,200
  • 21
  • 280
  • 313