Vim:t_Co=256 和 term=xterm-256color 与 TMUX 的区别 [英] Vim: Difference between t_Co=256 and term=xterm-256color in conjunction with TMUX

查看:118
本文介绍了Vim:t_Co=256 和 term=xterm-256color 与 TMUX 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试各种不同的终端,我倾向于使用这些终端通过 SSH 连接到我设置了 Tmux 的 Linux 机器.

I am testing the various different terminals that I tend to use to SSH into Linux boxes that I have Tmux set up on.

基本上我注意到了这种行为,我希望有人可以解释发生了什么.现在可能是这种情况是影响提示应用程序的特定行为.

Basically I noticed this behavior, and I am hoping that somebody could offer an explanation of what's going on. Now it may be the case that this is specific behavior that affects the Prompt app.

我在 Tmux 中使用 Vim,并且在我的 iPhone5 上的 Panic 提示应用程序上,当 .vimrc 使用 set t_Co 设置颜色时,我的行为没有启用 256 种颜色=256 指令.在这里,当 Vim 没有通过 Tmux 运行时,它正确地显示了颜色.此外,OS X 的 Terminal.app 使用 Tmux 中的 Vim 正确呈现了颜色(不幸的是,我没有在 Windows 上用这个测试 PuTTY).

I am using Vim within Tmux, and on Panic's Prompt app on my iPhone5 I was having the behavior that 256 colors were not enabling when the .vimrc set the colors using the set t_Co=256 directive. Here, Vim was correctly displaying the colors when it was not run through Tmux. Also, OS X's Terminal.app correctly rendered the colors (I did not test PuTTY with this on windows unfortunately) with Vim in Tmux.

然后我将 set t_Co=256 替换为 set term=xterm-256color,现在颜色在通过 Tmux 使用 Vim 时起作用.

Then I swapped out set t_Co=256 for set term=xterm-256color and now the colors work when using Vim through Tmux.

另请注意,我测试了 Tmux 的 set -g default-terminal "xterm-256color"set -g default-terminal "screen-256color" 设置和这种变化对行为没有影响.

Note also that I tested both set -g default-terminal "xterm-256color" and set -g default-terminal "screen-256color" settings for Tmux and this change had no effect on behavior.

推荐答案

当你不使用 tmuxscreen 时,你只需要配置你的终端模拟器通过将它们的 TERM 设置为 xterm-256color 或任何适用于您的终端和平台的类似值,将自己宣传为能够显示 256 种颜色".你怎么做将取决于终端模拟器,不在你的问题和这个答案的范围内.

When you don't use tmux or screen, you only need to configure your terminal emulators to advertise themselves as "capable of displaying 256 colors" by setting their TERM to xterm-256color or any comparable value that works with your terminals and platforms. How you do it will depend on the terminal emulator and is outside of the scope of your question and this answer.

你不需要在 Vim 中做任何事情,因为它完全有能力自己做正确的事情.

You don't need to do anything in Vim as it's perfectly capable to do the right thing by itself.

当您使用 tmuxscreen 时,这些程序会为 $TERM 设置自己的默认值,通常是 screen,Vim 对它所提供的信息进行处理.

When you use tmux or screen, those programs set their own default value for $TERM, usually screen, and Vim does what it has to do with the info it is given.

如果您想要更统一(和丰富多彩)的行为,您必须将它们配置为对 $TERM 使用更好"的值:

If you want a more uniform (and colorful) behavior, you must configure them to use a "better" value for $TERM:

  • tmux

将此行添加到~/.tmux.conf:

set -g default-terminal "screen-256color"

  • 屏幕

    将此行添加到~/.screenrc:

    term "screen-256color"
    

  • 现在,两个多路复用器都会告诉 Vim 它们支持 256 种颜色,而 Vim 会做你期望它做的事情.

    Now, both multiplexers will tell Vim they support 256 colors and Vim will do what you expect it to do.

    编辑

    我的回答假设您可以编辑这些配置文件,但是,由于您可以编辑 ~/.vimrc,因此我认为我离目标不远了.

    My answer assumes that you are able to edit those configuration files but, since you are able to edit your ~/.vimrc, I don't think that I'm that far off the mark.

    编辑 2

    term 选项的值(用 &term 检索)是 Vim 在启动时选取的终端名称.该名称是您应该在终端模拟器中设置的名称.

    The value of the term option (retrieved with &term) is the name of the terminal as picked up by Vim upon startup. That name is what you are supposed to setup in your terminal emulator itself.

    t_Co 选项 (&t_Co) 的值是 Vim 认为主机终端可以显示的最大颜色数.根据terminfo$TERM对应的条目定义:

    The value of the t_Co option (&t_Co) is what Vim considers to be the maximum number of colors that can be displayed by the host terminal. It is defined according to the entry corresponding to $TERM in terminfo:

     term            | t_Co
    -----------------+------ 
     xterm           | 8
     xterm-256color  | 256
     screen          | 8
     screen-256color | 256
    

    当 Vim 启动时,它获取 TERM 环境变量的值,用该值查询 terminfo 数据库,并将有关其环境的许多信息存储在几个t_... 变量,其中... t_Co 中可用的颜色数量.给定一个合法的"终端类型(Vim 可以查找的类型),Vim 总是假定正确的颜色数量.

    When Vim starts up, it gets the value of the TERM environment variable, queries the terminfo database with that value and stores a number of informations on its environment in several t_… variables among which… the number of colors available in t_Co. Given a "legal" terminal type (one that Vim can lookup), Vim always assumes the correct number of colors.

    t_Co 设置为 256 而将 term 保留为其 Vim 定义的值——或者,更一般地说,设置 t_Co 和/或 term 到与主机终端不匹配的值 - 没有意义,并且可能会在 Vim 发送终端无法理解的信号时产生麻烦,反之亦然.

    Setting t_Co to 256 while leaving term to its Vim-defined value — or, more generally, setting t_Co and/or term to values that don't match with the host terminal — makes no sense and will likely create troubles when Vim sends a signal that is not understood by the terminal or vice-versa.

    虽然完全有可能这样做,但在 Vim 中使用 t_Coterm 是完全没有用的,而且可能有害.

    While it is entirely possible to do so, messing with t_Co and term in Vim is both totally useless and possibly harmful.

    同样,只需正确设置您的终端仿真器和终端多路复用器.这就是真的你所需要的.

    Again, just setup your terminal emulators and terminal multiplexers correctly. That's really all you need.

    如果你在终端多路复用器或终端模拟器中无法定义正确的TERM,那么只有这样你才能强制 Vim 假设为 256颜色.为此,改变 t_Co 的值是唯一有意义的事情:

    If you end up in a terminal multiplexer or a terminal emulator where you can't define a correct TERM, then and only then you can force Vim to assume 256 colors. To that end, changing the value of t_Co is the only thing that makes sense:

    if &term == "screen"
      set t_Co=256
    endif
    

    所以……如果您可以配置每个单独的部分:

    So… if you can configure each individual part:

    • 终端模拟器:xterm-256color
    • tmux/screen: screen-256color
    • vim:没什么

    你就完成了.

    如果你不能控制每一个部分,在你的~/.vimrc中使用一个简单的条件来根据设置t_Co>&term 但不要改变 term 的值.

    If you can't control every part, use a simple conditional in your ~/.vimrc to set t_Co according to &term but don't change the value of term.

    但是如果您可以编辑 ~/.vimrc,那么您就没有理由不能编辑 ~/.screenrc~/.tmux.conf~/.bashrc 或其他.

    But if you can edit a ~/.vimrc there's no reason you can't edit a ~/.screenrc or ~/.tmux.conf or ~/.bashrc or whatever.

    这篇关于Vim:t_Co=256 和 term=xterm-256color 与 TMUX 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆