V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
7RTDKSAK
V2EX  ›  问与答

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

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

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

    也问了 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  
       7 天前
    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   ·   实用小工具   ·   5467 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 06:09 · PVG 14:09 · LAX 23:09 · JFK 02:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.