繁体   English   中英

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

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

我看到过很多没有启用“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

导致 vim 具有奇怪的颜色 output - 通常使用 tmux。

最初我也发现了成功。 直到有一天(说真的)vim 开始表现得很奇怪。 但以不同的方式。 它变成单色。

如果我没有设置它,即se notgc ,我实际上得到了正确的配色方案。 这在 vim + tmux 用法中也完全相同。

但是,当我使用 vim + tmux 时,如果我杀死一个窗格,或者重新加载 ~/tmux.config,现有的 vim 会话又变得奇怪了!

是一个这样的事件,左边是一个新打开的缓冲区,而右边的,具有相同的设置,突然变得奇怪。

我的设置:

  • 这是我公司的工作服务器,我没有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 --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

默认的 cshrc 将 TERM 显式设置为vt100 如果我将其更改为xterm-256colorscreen-256color ,我实际上在 vim 内获得了良好的配色方案,并且:set term=$TERM或明确地设置为上述两者之一,出现相同的问题。

  • TMUX v2.3,尝试了以下内容:
set -g default-terminal "screen/xterm-256color" 
set -ga terminal-overrides ",*256col*:Tc"
  • 我使用 gnome-terminal(v2.31.3),我还尝试了 Konsole(v 2.3.3, Qt: 4.6.2, KDE: 4.3.4) - 在这里我没有看到问题,但是,konsole 非常慢通过我的 vnc 连接,gnome-terminal 不是这种情况。 所以我决定坚持下去。

-- 关于颜色支持:没有真正的颜色支持,因为

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";
}

返回这个。 Konsole 返回更平滑的output

我应该放弃 gnome-terminal 并尝试一些其他模拟器(比 Konsole 更快)吗? 如果可以在 gnome-terminal 本身中找到解决方案,我将不胜感激。

我希望我已经提供了所有相关细节,谢谢

以下组合应该适用于大多数情况:

~/.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' "

请注意,这不会vim中硬编码任何颜色配置,这是一种干净的方法。 您永远不必强制vim使用 256 色。 终端负责告诉 vim 是否支持 256 colors。

这种方法也不会在tmux中硬编码任何颜色配置。 不过,在某些情况下强制 tmux 使用 256 色可能是有意义的。 如果你想这样做,只需删除if

~/.tmux.conf:

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

我相信这部分是由于您的 tmux 配置所致。 您需要在.tmux.conf中设置以下内容:

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

请注意,您不能在默认终端选项中使用斜杠,因为它必须是有效的终端类型。 我假设您登录的所有系统都具有screen-256color终端类型,但您可以通过运行infocmp screen-256color进行检查,它应该在成功时打印终端信息,在出错时打印错误。 您可能需要安装其他软件包才能添加该终端类型。

至于 GNOME 终端,2.31 已经很老了。 GNOME 2 中使用的 VTE 版本绝对不支持真正的 colors。理想情况下,您可以将本地系统设置为使用现代终端仿真器并通过 SSH 登录而不是使用 VNC,一切都会正常进行。

我会很清楚,因为您在这里使用的是 CentOS 或 RHEL 6,所以您尝试使用的几乎所有终端仿真器都可能会损坏。 这个操作系统已有十年历史,到 11 月将失去安全支持。 如前所述,您最好的选择是在笔记本电脑或台式机上使用更现代的环境并通过 SSH 登录。

暂无
暂无

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

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