kovidgoyal / kitty

Cross-platform, fast, feature-rich, GPU based terminal
https://sw.kovidgoyal.net/kitty/
GNU General Public License v3.0
24.62k stars 987 forks source link

Italics not rendered in vim #3918

Closed lierdakil closed 3 years ago

lierdakil commented 3 years ago

Describe the bug

Italic font is not rendered in vim despite all relevant settings apparently in place; it works with other terminals or when terminfo isn't prefixed by xterm-. The latter makes me suspect something here falls back to xterm terminfo.

To Reproduce

Steps to reproduce the behaviour (assuming italic font is set up and working in kitty):

  1. Set vim to highlight, e.g. comments, with cterm=italic by adding to .vimrc:
    highlight Comment cterm=italic gui=italic
  2. Open test.sh
  3. Add a line starting with #
  4. Expected: commend rendered as italic Actual: comment is not rendered as italic

However, everything works as expected if terminfo is recompiled without xterm- prefix in the name.

Screenshots

Kitty rendering italics outside vim: image

Kitty not rendering italics in vim: image

Other terminal (alacritty) rendering the same file opened in vim (the colour is unfortunate, sorry): image

Kitty with TERM=kitty rendering italics in vim: image

Environment details

kitty 0.22.2 created by Kovid Goyal
Linux livid.lan 5.10.52-gentoo #1 SMP Mon Aug 9 10:09:38 MSK 2021 x86_64
This is \n.\O (\s \m \r) \t
DISTRIB_ID="Gentoo"
Running under:X11
Loaded config files:
  /home/livid/.config/kitty/kitty.conf

Config options different from defaults:
background_opacity    0.85
bold_font             Victor Mono Bold
bold_italic_font      Victor Mono Bold Italic
cursor_blink_interval 0.0
enable_audio_bell     False
font_family           Victor Mono Medium
font_size             15.75
italic_font           Victor Mono Medium Italic
visual_bell_duration  0.2
window_padding_width  FloatEdges(left=1.5, top=1.5, right=1.5, bottom=1.5)
Added shortcuts:
    ctrl+c KeyAction('copy_or_interrupt')
Changed shortcuts:
    shift+ctrl+enter KeyAction('new_os_window_with_cwd')
Colors:
    background            #282c34   
    color0                #282828   
    color1                #f43753   
    color10               #c9d05c   
    color11               #ffc24b   
    color12               #b3deef   
    color13               #d3b987   
    color14               #73cef4   
    color2                #c9d05c   
    color3                #ffc24b   
    color4                #b3deef   
    color5                #d3b987   
    color6                #73cef4   
    color7                #eeeeee   
    color8                #484848   
    color9                #f43753   
    foreground            #abb2bf   

Additional context

.vimrc line to enable italics on, say, comments:

highlight Comment cterm=italic gui=italic

First line of dumping vim output (via vim test.sh | tee /tmp/vim.dump):

^[[?1049h^[[22;0;0t^[[?1h^[=^[[1;48r^[[27m^[[24m^[[23m^[[0m^[[H^[[2J^[[?25l^[[48;1H"test.sh" 2L, 23C^[[1;1H^[[3m^[[34m#!/bin/bash -e^[[23m^[[0m

The full dump is attached: vim.txt

Notice that running head -n1 vim.txt draws italic font correctly.

VIM version:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Aug  9 2021 07:58:13)
Included patches: 1-814
Modified by Gentoo-8.2.0814-r100
Compiled by livid@localhost
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        -terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
+clientserver      +job               +persistent_undo   -toolbar
+clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       -lua               -ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       +X11
-dnd               +mouse             -sound             +xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              -mouse_gpm         +statusline        +xsmp_interact
+ex_extra          -mouse_jsbterm     -sun_workshop      +xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: x86_64-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -pipe -march=native -mtune=native -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: x86_64-pc-linux-gnu-gcc   -Wl,-O1 -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lelf   -lacl -lattr -ldl     -lpython3.9 -lcrypt -lpthread -ldl -lutil -lm -lm  
kovidgoyal commented 3 years ago

vim (8.2.2891) renders italics in kitty with the default TERM of term-kitty fine for me.

vim -u NONE --cmd 'syntax on' --cmd 'highlight Comment cterm=italic gui=italic' t.sh

Where t.sh contains some comments.

In any case, this is a vim issue as kitty does not condition any behavior on the basis of TERM values. Only vim can do that. You would need to ask its developers about it.

And note that if you want to create a dump of the exact bytes a program is sending kitty, use --dump-bytes

lierdakil commented 3 years ago

Sorry for the non-issue. Thank you for pointing me in the right direction.

For posterity, in case someone runs into this.

This apparently happens because vim tests terminal background colour if TERM starts with xterm. By default, vim assumes background is light (with a few exceptions), so after testing it is changed to dark if vim thinks it's actually dark (but that is determined by questionable heuristics).

This is all fine and good, but this happens long after .vimrc is run, and setting background triggers syntax theme reset, so any changes made in .vimrc are lost.

The reason why alacritty wasn't affected is apparently because if TERM doesn't start with xterm, vim doesn't run this code path and just assumes background is light (with a couple exceptions based on TERM value).

Ways to work around this:

  1. Set background explicitly in .vimrc before messing with highlight commands, e.g. set background=dark. Or use a colour scheme that sets background.
  2. Run highlight commands from autocommand event OptionSet background, e.g. au OptionSet background highlight ...

FWIW, option (2) is very brittle.