需要对tmux进行一些澄清

时间:2018-06-08 05:11:47

标签: vim configuration tmux

我今天刚刚安装了tmux,我在使用它时遇到了一些困难。 在终端窗口的最底部(我使用iTerm2),它说如下:[13] 0:zsh*

13是什么意思?我知道节省了13件事。我不知道它们是窗户,窗格还是会话。我不知道;我想清除它们,即我希望它说[0] 0:zsh*

另外,vim在tmux中看起来很糟糕。我已经看到你需要运行命令:set -g default-terminal "screen-256color"但它不起作用。 vim-airline看起来也很糟糕。但是,如果没有运行tmux,vim看起来就好了。如果有人能为我回答这个问题,那就太棒了:)。

更新:

我尝试使用tmux -2命令,但这也无效。 vim看起来仍然很糟糕,在输入echo $TERM后,我得到了screen而不是screen-256-color

1 个答案:

答案 0 :(得分:3)

当我遇到这个问题时,那是因为我的vim colorscheme使用的是truecolor(24位),而tmux只支持8bit(256色)。

以下是检查颜色支持的方法:

首先,确保您的默认终端支持256色,使用此python脚本支持tmux:

#!/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中是否支持truecolor:

#!/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";
}'

这个的预期输出如下:

enter image description here

预期的行为是tmux将支持256色但不支持truecolor,并且您的终端将支持这两种颜色。如果这是真的,并且你的vim colorscheme仍然看起来很糟糕,很可能你正在使用truecolor colorscheme而tmux不能支持它。您可以切换到256色版本,或者只是为此感到难过。抱歉缺少好消息。

相关问题