Can I get italics in gnome-terminal?

5,370

Solution 1

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.

Solution 2

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.

Share:
5,370
Chronos
Author by

Chronos

Updated on September 18, 2022

Comments

  • Chronos
    Chronos over 1 year

    After a lot of searching I cannot find a way to get gnome-terminal to display italic fonts. I'm running version 3.6.2.

    Specifically I would like vim to display comments in italics; I've added

    highlight Comment cterm=italic
    

    to my .vimrc but it doesn't work.

    Does anyone know if this can be done?

  • Chronos
    Chronos over 9 years
    Thank you for your answer, and apologies for not acknowledging it sooner. I have switched to using Urxvt; it is highly customizable, and with a bit of effort I was able to make it look almost exactly like my old gnome-terminal set-up.
  • Chronos
    Chronos over 9 years
    Thank you! The set commands were what I was missing in my vimrc. Now my comments in terminal vim are italicized, just the way I like 'em.
  • Jeremy West
    Jeremy West about 9 years
    Don't miss that Note about ^[ or you'll be confused for a long time!
  • nehan
    nehan over 8 years
    gnome terminal 3.6.2 does also support italic! finally, i have italics in markdown, thanks!