5

Vim (v 8.0.1283) is drawing 8-bit color in iTerm2 (v 3.2.4) despite what appears to be correct configuration. $TERM is set correctly:

$ echo $TERM
xterm-256color

Here's the relevant section of my ~/.vimrc:

set background=dark
set termguicolors
colorscheme deep-space

The repo for this theme doesn't point to any further config for the vimrc. Even more confusing, the themes are pulled from rafi/awesome-vim-colorschemes with vim-plug and many of these theme work perfectly. The docs say the plugin requires true color (which I'm assuming is 256).

I've tried restarting and sourcing the vimrc, triple checked spelling and env variables, re-read documentation for the color scheme but can't seem to make heads or tails of it. Is there something obvious I'm missing here?

0

1 Answer 1

5

True color (24 bit) is not 256 color (8 bit). Copied from another of my answers:

When I had this problem, it was because my vim colorscheme was using truecolor (24 bit) and tmux only supports 8bit (256 colors).

Here are the methods to check color support:

First, make sure you have 256 color support in your default terminal and tmux with this python script:

#!/usr/bin/env python
# Copyright (C) 2006 by Johannes Zellner, <[email protected]>
# modified by [email protected] to fit my output needs
# modified by [email protected] to fit my output needs

import sys
import os

def echo(msg):
    os.system('echo -n "' + str(msg) + '"')

def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")

# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)

echo("\n")
echo("\n")

y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1

    echo("\n")


echo("\n")

for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")

echo("\n")
os.system("tput setaf 7")
os.system("tput setab 0")

The expected output is to have each line be a different color, with a max of 1 white line. If there are more lines with white text on black background, you do not have 256 colors enabled.

Next, check that you have truecolor support in your terminal/tmux with this bash script:

#!/bin/bash
# Based on: https://gist.github.com/XVilka/8346728

awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
    s="/\\";
    for (colnum = 0; colnum<term_cols; colnum++) {
        r = 255-(colnum*255/term_cols);
        g = (colnum*510/term_cols);
        b = (colnum*255/term_cols);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum%2+1,1);
    }
    printf "\n";
}'

The expected output of this one looks like this:

enter image description here

The expected behavior is that tmux will support 256 color but not truecolor, and that your terminal will support both. If this is true, and your vim colorscheme still looks bad, it is very likely that you are using a truecolor colorscheme and tmux cannot support that. You can either switch to a 256 color version or just be sad about it. Sorry for the lack of good news.

2
  • Appreciate the answer. Running the scripts show that my terminal is supporting both true color and 256. Editing my question title though to be more accurate. Commented Nov 16, 2018 at 19:03
  • The good news, however, is that tmux still can made to support truecolor: medium.com/@dubistkomisch/…
    – A S
    Commented Nov 16, 2018 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.