Vim colors not working properly in terminal

22

13

I'm using gnome terminal, and vim with solarized color theme. When I open vim in the terminal, it's illegible.

vim opened in the terminal

But when I open a file in gvim, the color scheme works perfectly.

gvim

Gnome terminal's color scheme is also solarized. One thing to note is that, if I set an illegal value for background, I get the expected background color (but also an error).

yasith

Posted 2011-12-21T22:00:20.843

Reputation: 359

Might I suggest installing terminator (a great, solid terminal emulator), and then going Preferences>Profiles>Colors>Palette and selecting Solarized. Additionally, (as I have it) you can go to Keybindings and map super+p or whatever you want to change to the next profile (which would contain a different profile). I have two profiles - solarized and another more colorful one that I do everything but vim in. Whenever I go into vim now, I simply hit super+p and then my palette matches that which the creator of solarized had intended. Cheers – dylnmc – 2015-10-12T12:24:22.710

Could you add your .vimrc and .gvimrc? – None – 2011-12-21T22:18:48.863

.vimrc is here there's no .gvimrc. I already checked the question on the 1st comment. My &term and $TERM are both the same (xterm-256color).

– None – 2011-12-21T23:59:44.717

1

Found a temporary fix, adding this before colorscheme solarized. Changes the colors to the solarized theme. But, the line numbers column keeps having a brownish-grey color.

– None – 2011-12-22T00:17:39.413

Answers

9

To complete Akira's advice, vim in term mode uses the terminal color palette. From the vim solarized colorscheme repo :

If you are going to use Solarized in Terminal mode (i.e. not in a GUI version like gvim or macvim), please please please consider setting your terminal emulator's colorscheme to used the Solarized palette. I've included palettes for some popular terminal emulator as well as Xdefaults in the official Solarized download available from Solarized homepage.

For gnome-term, there are instructions to set up the color palette.

Bathz

Posted 2011-12-21T22:00:20.843

Reputation: 385

See akira’s answer below for the magic incantation: export TERM=xterm-256color vim (and then put the export command in your shell startup file, like bashrc). – Ahmed Fasih – 2016-08-03T04:08:55.343

Had the same problem today, when trying to setup a new system, and after setting the colors in ~/.Xresources and merging using xrdb. The color problems with vim in terminal session is gone. – yasith – 2012-08-19T00:30:55.090

Useful gconf code block to set up gnome-terminal: http://www.xorcode.com/2011/04/11/solarized-vim-eclipse-ubuntu/

– artfulrobot – 2013-02-28T23:21:51.767

17

vim use the power of your "terminal" to draw the characters onto the screen. thus, how the drawn chars look depend largely on what the "terminal" is capable of. the "terminal" uses an enviroment variable to tell the apps running inside it about its capabilities: TERM.

if you want to use vim to use 256 colors you need 2 things:

  • a terminal capable of rendering at least 256 colors
  • the right TERM variable (xterm-256color)

so, try this:

$ export TERM=xterm-256color
$ vim

also read up more upon the topic on http://vim.wikia.com/wiki/256_colors_in_vim

akira

Posted 2011-12-21T22:00:20.843

Reputation: 52 754

even with 256 colors, a lot of colorschemes look off.. but I guess that is explained by the color palette – Emile 81 – 2017-01-11T09:15:21.867

1By running this commmand, I was able to use the vim extension Powerline in my gnome-terminal. Thank you! – Yamaneko – 2013-03-11T17:59:36.707

0

Referencing: https://unix.stackexchange.com/questions/66579/how-do-i-get-the-solarized-colour-scheme-working-with-gnome-terminal-tmux-and-v/141624#141624

I give the same response here: According to Koraktors comment, executeing :set t_Co=16 fixed the mixed colors issue immediately for me, so I added it to ~/.vimrc to sustain the correction.

You really don't want to enable the 256 colors, it actually decrease the how close you can get to the solarized pallette. From the devs website:

IMPORTANT NOTE FOR TERMINAL USERS:

If you are going to use Solarized in Terminal mode (i.e. not in a GUI version like gvim or macvim), please please please consider setting your terminal emulator’s colorscheme to used the Solarized palette. I’ve included palettes for some popular terminal emulator as well as Xdefaults in the official Solarized download available from Solarized homepage. If you use Solarized without these colors, Solarized will need to be told to degrade its colorscheme to a set compatible with the limited 256 terminal palette (whereas by using the terminal’s 16 ansi color values, you can set the correct, specific values for the Solarized palette).

Zak

Posted 2011-12-21T22:00:20.843

Reputation: 115

-3

Workaround for the grey number background color:

Open solarized.vim, search for LineNr, remove the line.

Westphal

Posted 2011-12-21T22:00:20.843

Reputation: 9