真彩色(24 位)不是 256 色(8 位)。复制自我的另一个答案:
当我遇到这个问题时,是因为我的 vim 颜色方案使用的是真彩色(24 位),而 tmux 只支持 8 位(256 色)。
以下是检查颜色支持的方法:
首先,请确保您的默认终端和 tmux 支持 256 色:
#!/usr/bin/env python
# Copyright (C) 2006 by Johannes Zellner, <johannes@zellner.org>
# modified by mac@calmar.ws to fit my output needs
# modified by crncosta@carloscosta.org 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")
预期的输出是每条线都是不同的颜色,最多有 1 条白线。如果黑底白字的行数较多,则说明您没有启用 256 色。
接下来,使用此 bash 脚本检查您的终端/tmux 中是否支持真彩色:
#!/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";
}'
这个的预期输出如下所示:
预期的行为是 tmux 将支持 256 色但不支持真彩色,并且您的终端将同时支持这两种颜色。如果这是真的,并且您的 vim 颜色方案仍然看起来很糟糕,那么您很可能正在使用真彩色颜色方案,而 tmux 无法支持它。您可以切换到 256 色版本,也可以为此感到难过。很抱歉没有好消息。