简体   繁体   English

vim:使用 xterm-true-color 的 termguicolors 仍然会导致问题

[英]vim: termguicolors with xterm-true-color still causing problems

I have seen a multitiude of posts where not enabling 'tgc' with:我看到过很多没有启用“tgc”的帖子:

if exists('+termguicolors')
   let &t_8f =  "\<Esc>[38:2:%lu:%lu:%lum"
   let &t_8b =  "\<Esc>[48:2:%lu:%lu:%lum"
   " let &t_8f =  "\<Esc>[38:2;%lu;%lu;%lum" ( I have tried both ':' and ';' )
   " let &t_8b =  "\<Esc>[48:2;%lu;%lu;%lum"
   set t_Co=256
   set termguicolors
   " colorscheme gruvbox " color scheme
 endif

causes vim to have weird color output - usually with tmux.导致 vim 具有奇怪的颜色 output - 通常使用 tmux。

Initially I found success with this too.最初我也发现了成功。 Until one fine day (seriously,) vim starts behaving weird.直到有一天(说真的)vim 开始表现得很奇怪。 but in a different way.但以不同的方式。 It goes monochrome.它变成单色。

If, I don't set it, ie se notgc , I actually get the right colorscheme.如果我没有设置它,即se notgc ,我实际上得到了正确的配色方案。 This is exactly the same in vim + tmux usage as well.这在 vim + tmux 用法中也完全相同。

But, when I use vim + tmux, if I, say, kill a pane, or reload ~/tmux.config, existing vim sessions get weird again!但是,当我使用 vim + tmux 时,如果我杀死一个窗格,或者重新加载 ~/tmux.config,现有的 vim 会话又变得奇怪了!

Here is a look at one such occurance, the left is a newly opened buffer, while the right one, with the same settings, suddenly goes weird.是一个这样的事件,左边是一个新打开的缓冲区,而右边的,具有相同的设置,突然变得奇怪。

My settings:我的设置:

  • This is my company work server, I don't have su permissions.这是我公司的工作服务器,我没有su权限。
$ cat /proc/version
Linux version 2.6.32-504.30.3.el6.x86_64 (mockbuild@c6b8.bsys.dev.centos.org) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Jul 15 10:13:09 UTC 2015
  • VIM VIM
vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jul 26 2019 22:56:22)
Included patches: 1
Compiled by bob@c6x64
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers                                                                                               [25/126]
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          +toolbar
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               -perl              +vertsplit
+clipboard         +jumplist          +persistent_undo   +virtualedit
+cmdline_compl     +keymap            +postscript        +visual
+cmdline_hist      +lambda            +printer           +visualextra
+cmdline_info      +langmap           +profile           +viminfo
+comments          +libcall           -python            +vreplace
+conceal           +linebreak         -python3           +wildignore
+cryptv            +lispindent        +quickfix          +wildmenu
+cscope            +listcmds          +reltime           +windows
+cursorbind        +localmap          +rightleft         +writebackup
+cursorshape       -lua               -ruby              +X11
+dialog_con_gui    +menu              +scrollbind        -xfontset
+diff              +mksession         +signs             +xim
+dnd               +mouse             +startuptime       +xsmp_interact                                                                                         
-ebcdic            +mouseshape        +statusline        +xterm_clipboard
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_save
+eval              +mouse_gpm         +syntax
+ex_extra          -mouse_jsbterm     +tag_binary
+extra_search      +mouse_netterm     +tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/tools/apps/local/vim/latest/share/vim"
Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freety
pe2 -I/usr/include/libpng12     -O2 -fno-strength-reduce -Wall -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim   -pthread -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixb
uf-2.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lgthread-2.0 -lrt -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -lti
nfo -lelf -lnsl  -lselinux -lacl -lattr -lgpm

The default cshrc had TERM explicitly set as vt100 .默认的 cshrc 将 TERM 显式设置为vt100 If I change it to xterm-256color or screen-256color , I actually get good colorschemes within vim, and :set term=$TERM or explicitly to either of the above two, with the same problems showing up.如果我将其更改为xterm-256colorscreen-256color ,我实际上在 vim 内获得了良好的配色方案,并且:set term=$TERM或明确地设置为上述两者之一,出现相同的问题。

  • TMUX v2.3, tried the following: TMUX v2.3,尝试了以下内容:
set -g default-terminal "screen/xterm-256color" 
set -ga terminal-overrides ",*256col*:Tc"
  • I use gnome-terminal(v2.31.3), I also tried Konsole(v 2.3.3, Qt: 4.6.2, KDE: 4.3.4) -- and here I am not seeing the issue, But, konsole is terribly slow over my vnc connection, which is not the case gnome-terminal.我使用 gnome-terminal(v2.31.3),我还尝试了 Konsole(v 2.3.3, Qt: 4.6.2, KDE: 4.3.4) - 在这里我没有看到问题,但是,konsole 非常慢通过我的 vnc 连接,gnome-terminal 不是这种情况。 so I decided to stick with it.所以我决定坚持下去。

-- On color support: No true color support since -- 关于颜色支持:没有真正的颜色支持,因为

awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        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+1,1);
    }
    printf "\n";
}

returns this.返回这个。 where as Konsole returns a much smoother output . Konsole 返回更平滑的output

Should I ditch gnome-terminal and try some other emulator (which is snappier than Konsole)?我应该放弃 gnome-terminal 并尝试一些其他模拟器(比 Konsole 更快)吗? I would really appreciate if a solution can be found within gnome-terminal itself.如果可以在 gnome-terminal 本身中找到解决方案,我将不胜感激。

I hope I have given all the relevant details, Thanks我希望我已经提供了所有相关细节,谢谢

The following combination should work in most scenarios:以下组合应该适用于大多数情况:

~/.vimrc:

" Inspect $TERM instad of t_Co as it works in neovim as well
if &term =~ '256color'
  " Enable true (24-bit) colors instead of (8-bit) 256 colors.
  " :h true-color
  if has('termguicolors')
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
    set termguicolors
  endif
  colorscheme <your favorite colorscheme goes here>
endif
~/.tmux.conf:

# Set $TERM and force 256 colors.
# https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-a-256-colour-terminal
# https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-rgb-colour
if "[[ $TERM =~ 256color]]" "
    set -g default-terminal 'tmux-256color';
    set -ga terminal-overrides ',tmux-256color:Tc' "

Note that this doesn't hard-code any color configuration in vim , which is a clean approach.请注意,这不会vim中硬编码任何颜色配置,这是一种干净的方法。 You should never have to force vim to use 256 color.您永远不必强制vim使用 256 色。 The terminal is responsible to tell vim whether 256 colors are supported or not.终端负责告诉 vim 是否支持 256 colors。

This approach also doesn't hard-code any color configuration in tmux .这种方法也不会在tmux中硬编码任何颜色配置。 It may make sense to force tmux to use 256 color in some scenarios, though.不过,在某些情况下强制 tmux 使用 256 色可能是有意义的。 If you want to do so, just remove the if :如果你想这样做,只需删除if

~/.tmux.conf:

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

I believe this is in part due to your tmux configuration.我相信这部分是由于您的 tmux 配置所致。 You'll want to set the following in .tmux.conf :您需要在.tmux.conf中设置以下内容:

set -g default-terminal screen-256color
set -ag terminal-overrides ",xterm-256color:Tc"

Note that you cannot use a slash in the default terminal option, since it must be a valid terminal type.请注意,您不能在默认终端选项中使用斜杠,因为它必须是有效的终端类型。 I assume all the systems you are logging into have the screen-256color terminal type, but you can check by running infocmp screen-256color , which should print terminal info on success and an error on error.我假设您登录的所有系统都具有screen-256color终端类型,但您可以通过运行infocmp screen-256color进行检查,它应该在成功时打印终端信息,在出错时打印错误。 You may need to install additional packages to add that terminal type.您可能需要安装其他软件包才能添加该终端类型。

As far as GNOME Terminal, 2.31 is very old.至于 GNOME 终端,2.31 已经很老了。 The VTE version used in GNOME 2 definitely does not support true colors. Ideally you'll set up your local system to use a modern terminal emulator and log in over SSH instead of using VNC, and things will work. GNOME 2 中使用的 VTE 版本绝对不支持真正的 colors。理想情况下,您可以将本地系统设置为使用现代终端仿真器并通过 SSH 登录而不是使用 VNC,一切都会正常进行。

I will be clear that since you're using CentOS or RHEL 6 here, that virtually any terminal emulator you're trying to use will likely be broken.我会很清楚,因为您在这里使用的是 CentOS 或 RHEL 6,所以您尝试使用的几乎所有终端仿真器都可能会损坏。 This OS is a decade old and will lose security support as of November.这个操作系统已有十年历史,到 11 月将失去安全支持。 Your best bet, as mentioned, is to use a more modern environment on your laptop or desktop and log in over SSH.如前所述,您最好的选择是在笔记本电脑或台式机上使用更现代的环境并通过 SSH 登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM