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 https://gist.githubusercontent.com/sadsfae/0b4dd18670639f7dce941a1b2a9e4e9e/raw/908b48e6b6370da0568be8d138966c60240a50dd/xterm-256color-italic.terminfo > 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.

Issues
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:

TERM=xterm-color

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, all-around nice guy.
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:

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s