Problem description
When opening Vim with xterm and a TERM value of xterm-direct, implying support for direct colours, Vim is unable to properly display colors, making it pretty much unusable.
Enabling termguicolors works as expected.
Proposed solution
According to XTerm's terminfo file, ncurses' 6.1 RGB capability is set when TERM is xterm-direct. Vim could detect this capability and automatically enable termguicolors to fix the issue.
Alternative solutions
Neovim has adopted a similar solution, but somewhat more extreme. In neovim/neovim#26407, they changed Neovim to enable termguicolors whenever possible. While it has its pros, I can understand why one would not want termguicolors always enabled, and I'm proposing to enable it only when the terminal is claiming direct colors support.
Neovim's will enable termguicolors when any of the following is true:
- The
TERM has a terminfo entry specifying ncurses' RGB capability
- The
TERM has a terminfo entry specifyng tmux's non-standard Tc capability
- The
TERM has a terminfo entry specifying the non-standard setrgbf and setrgbb capabilities
- The
COLORTERM environment variable is set to truecolor or 24bit
I'm personally against using the COLORTERM environment variable to check for terminal capabilities. We already have the terminfo database for that. As for Tc, it's non-standard and tmux itself considers it redundant now that RGB exists. Lastly, setrgbf and setrgbb are non-standard too, but have their merits. I'm unsure whether Vim should support them though.
As a temporary workaround, in my vimrc I have set the following:
if has('termguicolors') && &t_Co == '16777216'
set termguicolors
endif
Additional context
$ xterm -version
XTerm(396)
$ vim --version
VIM - Vi IMproved 9.1 (2024 Jan 02, compiled Jun 24 2024 14:19:35)
Included patches: 1-496
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version with GTK3 GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_urxvt -tag_any_white
+arabic +find_in_path +mouse_xterm +tcl
+autocmd +float +multi_byte +termguicolors
+autochdir +folding +multi_lang +terminal
-autoservername -footer -mzscheme +terminfo
+balloon_eval +fork() +netbeans_intg +termresponse
+balloon_eval_term +gettext +num64 +textobjects
+browse -hangul_input +packages +textprop
++builtin_terms +iconv +path_extra +timers
+byte_offset +insert_expand +perl +title
+channel +ipv6 +persistent_undo +toolbar
+cindent +job +popupwin +user_commands
+clientserver +jumplist +postscript +vartabs
+clipboard +keymap +printer +vertsplit
+cmdline_compl +lambda +profile +vim9script
+cmdline_hist +langmap -python +viminfo
+cmdline_info +libcall +python3 +virtualedit
+comments +linebreak +quickfix +visual
+conceal +lispindent +reltime +visualextra
+cryptv +listcmds +rightleft +vreplace
+cscope +localmap +ruby +wildignore
+cursorbind +lua +scrollbind +wildmenu
+cursorshape +menu +signs +windows
+dialog_con_gui +mksession +smartindent +writebackup
+diff +modify_fname +sodium +X11
+digraphs +mouse +sound +xattr
+dnd +mouseshape +spell -xfontset
-ebcdic +mouse_dec +startuptime +xim
+emacs_tags +mouse_gpm +statusline -xpm
+eval -mouse_jsbterm -sun_workshop +xsmp_interact
+ex_extra +mouse_netterm +syntax +xterm_clipboard
+extra_search +mouse_sgr +tag_binary -xterm_save
-farsi -mouse_sysmouse -tag_old_static
system vimrc file: "/etc/vim/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
3rd user vimrc file: "$XDG_CONFIG_HOME/vim/vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "/etc/vim/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
3rd user gvimrc file: "$XDG_CONFIG_HOME/vim/gvimrc"
defaults file: "$VIMRUNTIME/defaults.vim"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/webp -I/usr/include/gio-unix-2.0 -I/usr/include/cloudproviders -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -pthread -Wdate-time -g -O2 -Werror=implicit-function-declaration -ffile-prefix-map=/build/reproducible-path/vim-9.1.0496=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -DSYS_VIMRC_FILE=\"/etc/vim/vimrc\" -DSYS_GVIMRC_FILE=\"/etc/vim/gvimrc\" -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lgtk-3 -lgdk-3 -lz -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -lselinux -lcanberra -lsodium -lacl -lattr -lgpm -L/usr/lib -llua5.1 -Wl,-E -fstack-protector-strong -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/perl/5.38/CORE -lperl -ldl -lm -lpthread -lcrypt -L/usr/lib/python3.12/config-3.12-x86_64-linux-gnu -lpython3.12 -ldl -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-3.1 -lm -L/usr/lib
Problem description
When opening Vim with xterm and a
TERMvalue ofxterm-direct, implying support for direct colours, Vim is unable to properly display colors, making it pretty much unusable.Enabling
termguicolorsworks as expected.Proposed solution
According to XTerm's terminfo file, ncurses' 6.1
RGBcapability is set whenTERMisxterm-direct. Vim could detect this capability and automatically enabletermguicolorsto fix the issue.Alternative solutions
Neovim has adopted a similar solution, but somewhat more extreme. In neovim/neovim#26407, they changed Neovim to enable
termguicolorswhenever possible. While it has its pros, I can understand why one would not wanttermguicolorsalways enabled, and I'm proposing to enable it only when the terminal is claiming direct colors support.Neovim's will enable
termguicolorswhen any of the following is true:TERMhas a terminfo entry specifying ncurses'RGBcapabilityTERMhas a terminfo entry specifyng tmux's non-standardTccapabilityTERMhas a terminfo entry specifying the non-standardsetrgbfandsetrgbbcapabilitiesCOLORTERMenvironment variable is set totruecoloror24bitI'm personally against using the
COLORTERMenvironment variable to check for terminal capabilities. We already have the terminfo database for that. As forTc, it's non-standard and tmux itself considers it redundant now thatRGBexists. Lastly,setrgbfandsetrgbbare non-standard too, but have their merits. I'm unsure whether Vim should support them though.As a temporary workaround, in my vimrc I have set the following:
Additional context