vim inside tmux 中 colorscheme 的颜色显示与 tmux 外部有差异,如何修复呢? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
7RTDKSAK
V2EX    问与答

vim inside tmux 中 colorscheme 的色显示与 tmux 外部有差异,如何修复呢?

  •  
  •   7RTDKSAK 2023-04-30 22:16:09 +08:00 1176 次点击
    这是一个创建于 894 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不是找不到答案,恰恰相反,是答案太多了,中英文合计有五六个修复方案

    也问了 GPT,它甚至从其中俩套修复方案中都各自抽取一部分出来以后拼凑了一个新方案给我

    所以懵逼了,有没有大佬解释一下为啥 tmux 内外的颜色会有差异?以及"必要且充分"地修复此问题地配置项都有几个?

    256COLOR 和 TRUE_COLOR 又是什么呢?

    4 条回复    2024-05-13 20:12:37 +08:00
    hanxiV2EX
        1
    hanxiV2EX  
       2023-04-30 22:23:28 +08:00   1
    曾经也遇到过很多次,现在使用 tmux 的配置搞定了。 在 bashrc 设置

    export TERM=tmux-256color

    在 tmux.conf 里配置

    set -g default-terminal "tmux-256color"
    set-option -ga terminal-overrides ',tmux-256color:Tc'
    set-option -ga terminal-overrides ',tmux-256color:RGB'

    也没去细研究过为啥,好像 tmux 有个 issues 说过的。
    7RTDKSAK
        2
    7RTDKSAK  
    OP
       2023-04-30 22:29:39 +08:00
    @hanxiV2EX

    好吧,又是一个新方案

    感觉来来回回就是那几个条目互相排列组合,产生了一堆修复方案

    也不知道到底哪几个条目才是必需地...逼死强迫症了哈哈哈...
    keyv
        3
    keyv  
       2023-05-01 10:46:24 +08:00   1
    如果想了解 true color 等相关概念,可以看一下 https://github.com/termstandard/colors

    只要确保终端和 tmux 中支持的色彩一致,tmux 内外颜色就不会有差异。可以用$TERM 这个环境变量确认一下。
    gleport
        4
    gleport  
       2024-05-13 20:12:37 +08:00
    tmux 的色彩和在终端上有差异的原因是:tmux 没有为终端开启 RGB 特性,本来应该是 RGB 24 位颜色的 ANSI 转义序列被 tmux 转换为比较接近的 256 色的转义序列,再输出给终端渲染。可以通过 `tmux -vvv` 启动日志查看 RGBCOLOURS flag 确认。

    tmux 也给用户提供了配置来开启 RGB 特性:set -as terminal-features ",根据自己的$TERM 值而定*:RGB"

    另外不推荐 export TERM=tmux-256color 这种方式修改 TERM 环境变量,这个值一般是终端模拟器初始化的时候终端自己设置的,许多外部程序会依赖这个值查询出对应的 terminfo ,从而确定终端特性能力以及在不同输入的行为,比如对 <CTRL>_l 这些控制序列的反应。正如 kitty 在这个配置上的警告说的:


    #: The value of the TERM environment variable to set. Changing this
    #: can break many terminal programs, only change it if you know what
    #: you are doing, not because you read some advice on "Stack Overflow"
    #: to change it. The TERM variable is used by various programs to get
    #: information about the capabilities and behavior of the terminal. If
    #: you change it, depending on what programs you run, and how
    #: different the terminal you are changing it to is, various things
    #: from key-presses, to colors, to various advanced features may not
    #: work. Changing this option by reloading the config will only affect
    #: newly created windows.

    我刚写了一篇 blog 来总结了一下 tmux 在不同终端下颜色差异的原因: https://hmgle.github.io/terminal/tmux/color/2024/05/12/term-color.html
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     978 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 51ms UTC 19:14 PVG 03:14 LAX 12:14 JFK 15:14
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86