Can I get italics in gnome-terminal?

Gnome terminal does support italics (at least in version 3.8.4). You can test terminal support for italics by executing $ echo -e "\e[3mfoo\e[23m". If you see foo printed in italics, foo, then terminal supports it.

Then you have to insert the following in .vimrc:

set t_ZH=^[[3m
set t_ZR=^[[23m

Note that ^[ is a single character and can in vim insert mode be inserted by typing <ctrl>-v <esc>.

After that you have to tell vim to italicize comments. You can quickly test if it works by executing :highlight Comment cterm=italic in vim when file with some comments is open. Comments should get italicized right away.

I found the above instructions on reddit (Italics in terminal vim and tmux), but I didn't have to follow all the steps listed there. My answer is the distilled version of instructions that worked for me.


No. I read man 5 terminfo to find out what the terminal ESCape sequences (what you send the terminal to cause the behavior) dealing with italics were called:

man 5 terminfo | egrep 'italics|Cap-|Code'|head -n 10| tail -n 4
               Variable                   Cap-            TCap               Description  
                String                    name            Code  
       enter_italics_mode                 sitm            ZH             Enter italic mode  
       exit_italics_mode                  ritm            ZR             End italic mode  

Then, I used infocmp to dump each terminal description so I could see which terminals supported italics:

for i in $( find /usr/share/terminfo -type f ) ; do 
    j=${i##*/}; hdr="$( infocmp $j | head -n 1)";  
    infocmp $j | egrep -q 'sitm|ZH' 
    if [ $? = 0 ] ; then echo $hdr; fi; 
done
# Reconstructed via infocmp from file: /usr/share/terminfo/r/rxvt-unicode-256color
# Reconstructed via infocmp from file: /usr/share/terminfo/o/opus3n1+
# Reconstructed via infocmp from file: /usr/share/terminfo/i/iris-color

So, these three terminal-types (rxvt-unicode-256color, opus3n1+, iris-color) support italics. Others do not.

Since I could not find a terminal definition for "gnome-terminal" (see ls /usr/share/terminfo/g/, I looked for italics in all. Try infocmp $TERM to see what capabilities your terminal supports. Read man tput to see how to emit control sequences.