簡體   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