Using Italics with Vim in your Terminal

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 > xterm-256color-italic

Now compile the terminfo file

tic xterm-256color-italic

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

If you use mutt for email, vim should be your default editor and it will also reflect in how quotes in replies are handled making them easier to read.

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:


Original credit for the terminfo goes to Nerdy Weekly.  You can read more about tricking out your vim editor here.

About Will Foster

hobo devop/sysadmin/SRE
This entry was posted in open source and tagged , , , , . Bookmark the permalink.

Have a Squat, Leave a Reply ..

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.