47

I have downloaded many vim color schemas and tried them out, but many of them don't look like the official screenshot.

For example, vim's own color schema - desert should look like this: desert color schema

But in my vim, many colors won't display, for example the background. my vim color display

But some color schemas work correctly.

Why is that?

In the: Edit-> Profile Preferences -> Colors, I select the "use colors from system theme"

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
Tanky Woo
  • 4,906
  • 9
  • 44
  • 75
  • I too have found this problem, and I am running the 256 color version of the terminal – puk Mar 23 '12 at 16:30
  • 3
    Best answer I've found: http://stackoverflow.com/a/15378816/357774 . Essentially, don't mess with `t_Co` in your .vimrc, just put this line in your .bashrc: `[[ -n "$DISPLAY" && "$TERM" = "xterm" ]] && export TERM=xterm-256color ` – Noyo Sep 09 '13 at 11:14
  • 26
    @moderators: How is this question off topic on a programming site? Vim is an extremely important productivity tool, as is tmux, and when used together the question of colorschemes operating correctly in terminal text mode is very relevant. The proof is that this question pops up on page 1 of a "256 colors in vim" google search. – Thomas Browne Nov 09 '14 at 12:54
  • 1
    Any news on this one? I installed the color theme both for Terminal.app and for vim. `$TERM` is set correctly, `t_Co` automatically set to 256, but colors are still broken. – Sebastian Graf Mar 25 '16 at 22:37

4 Answers4

62

Many colorschemes are designed for 256 colors, which is significantly better than a standard 8 color terminal. To make that work, you need $TERM set to a 256 color terminal like xterm-256color.

If you have a 256 color capable terminal (looks like you do from your screenshot if that is Gnome Terminal), set the $TERM to xterm-256color and enable 256 colors in your vimrc with something like:

if $TERM == "xterm-256color"
  set t_Co=256
endif

The Vim wiki has some tips on setting the correct $TERM for different terminal emulators. The easiest way to test this out quickly is to do

TERM=xterm-256color vim 

This will not make colorschemes designed for GUI vim fully compatible with terminal Vim, but will make 256-color colorschemes work, and those are a giant improvement over the standard 8 color colorschemes.

Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
  • changing my term to xterm-256color fixed all my issues when I had the same problem as @tanky-woo – arajek Mar 24 '12 at 16:31
  • 2
    This had been made me annoyed for years! Finally I found the root cause! I wish I had searched for this topic earlier. – Tyler Liu Apr 18 '13 at 03:05
  • 12
    More thorough answer: http://stackoverflow.com/a/15378816/357774 . Essentially, don't mess with `t_Co` in your .vimrc, just put this line in your .bashrc: `[[ -n "$DISPLAY" && "$TERM" = "xterm" ]] && export TERM=xterm-256color ` – Noyo Sep 09 '13 at 11:13
  • 1
    Messing with `t_Co` is fine, don't mess with `$TERM` - it does more than just dealing with colors –  Jul 23 '15 at 16:25
  • how... did... I... not.. know... about... this? – MK. Apr 27 '16 at 15:58
  • This still doesn't work for me, I've done all this and my color schemes still look weird. Any idea what's happening? – Addison Jun 22 '16 at 17:00
  • @Addison It's hard to say without knowing anything more about your setup. – Michael Berkowski Jun 22 '16 at 17:42
  • Oh actually I think the problem is the themes I was using were 16 colors. I looked for some 256 color themes and they work fine – Addison Jun 23 '16 at 00:15
20

On *nix systems, the very purpose of setting the $TERM environment variable to a terminfo entry that describes your terminal's capabilities, including the number of supported colors is to advertise these capabilities to the applications that will run inside your terminal.

In other words, the reason you set this variable in the first place is to tell Vim (or mutt.. slrn.. ELinks.. etc.) .. Hey.. among other things.. I support 256 colors, did you know..?

As a result, there is no point whatsoever in adding bloat to your vimrc to test the value of $TERM in order to set the value of the t_Co Vim variable. Vim is smart enough to pick up the supported number of colors from the terminfo entry pointed to by the $TERM variable. That's why you set it in the first place..!

In this respect, terminal/console Vim simply follows the *nix model and determines the terminal's capabilities from the terminfo entry and automatically sets the contents of the t_Co variable.

Tried and tested on something like 15 different terminal emulations in a GNU/linux environment.

guv'
  • 1,359
  • 13
  • 8
18

The first screenshot is GVim, not terminal Vim. Terminals are very limited when it comes to colour support. And GVim can use full RGB space.

Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • Nice catch! You are 100% correct, I didn't notice that when first reading through the question :) – Shane Feb 19 '18 at 21:36
6

The other answers here are good; I've also found this page very useful for tweaking and understanding the why's and how's of color environments for vim.

David Pope
  • 6,457
  • 2
  • 35
  • 45