I wanted all code, system configuration file comments or in-line replies in neomutt email italicised to stand out easier. Many terminal emulators (xterm, xfce4-terminal, iterm2) don’t support [3m and [23m designators for italics but you can use a custom terminfo to do the trick. Here’s how to get it working.
Determine if your Terminal is Supported
You can run the following command in your terminal to see if it already supports italics:
echo -e "\e[3m is this italics? \e[23m"
If you don’t see something like this you’ll need to make some adjustments. I believe as of writing this gnome-terminal, konsole and urxvt support this.
Install Custom Terminfo
If you didn’t print an italicised string above then you’ll need a custom terminfo file loaded. Be sure to do this for both your normal user and the root user if you sudo to root on a normal basis in an xterm.
curl https://gist.githubusercontent.com/sadsfae/0b4dd18670639f7dce941a1b2a9e4e9e/raw/908b48e6b6370da0568be8d138966c60240a50dd/xterm-256color-italic.terminfo > xterm-256color-italic
Now compile the terminfo file
Lastly, load it into your ~/.bashrc
echo "export TERM=xterm-256color-italic" >> ~/.bashrc source !$
Now you should have italics support in your terminal, try the test above to make sure.
Enabling Italics for Code Comments in Vim
The main reason I wanted italics support is so code comments and configuration file comments would stand out more clearly.
You can use the following command to enable this while inside vim:
:highlight Comment cterm=italic
To make it persistent:
echo "highlight Comment cterm=italic" >> ~/.vimrc
Enabling Italics in Tmux
If you use tmux and want to have support for italics you also need to add this to your ~/.tmux.conf configuration file.
set -g default-terminal "xterm-256color-italic"
If you see this error on a remote server when attaching to a screen or tmux session:
[sadsfae@bastion ~]$ screen -rx root/ Cannot find terminfo entry for 'xterm-256color-italic'
Set another TERM entry instead: