Skip to content

Instantly share code, notes, and snippets.

@tehmachine
Last active November 28, 2020 21:57
Show Gist options
  • Save tehmachine/93aee04ee14fd11dd576c674cf791994 to your computer and use it in GitHub Desktop.
Save tehmachine/93aee04ee14fd11dd576c674cf791994 to your computer and use it in GitHub Desktop.

Using Italics with Vim in your Terminal

Source: https://hobo.house/2017/07/17/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

Example 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. Example

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment