08 October 2015

Using italic fonts inside tmux.

A while back, I started using versions of the Inconsolata font that contains italic and bold italic variants. I find this particularly nice for things such as code comments, such as in this screenshot. To get this working, I followed the instructions on pages such as this one, which describes how to set up a terminfo file which understands italics.

Italic comments in Vim.

This is great, and works easily in a terminal like Konsole. However, I started noticing that it didn't work so well inside tmux. In fact, I was getting this instead:

No italic comments inside tmux.

The issue is apparently that tmux does not pass through all escape codes to the underlying terminal, but interprets them for itself. This article describes this. It also provides a solution. Wrapping the escape string in \ePtmux;\e and \e\ will tell tmux to just pass the escape codes straight through.


sitm=\E[3m, ritm=\E[23m,


sitm=\ePtmux;\e\E[3m\e\\, ritm=\ePtmux;\e\E[23m\e\\,

Here is the full resulting tmux-256color-italic file:

# A xterm-256color based TERMINFO that adds the escape sequences for italic.
# Install:
#   tic xterm-256color-italic.terminfo
# Usage:
#   export TERM=xterm-256color-italic
tmux-256color-italic|tmux with 256 colors and italic,
        sitm=\ePtmux;\e\E[3m\e\\, ritm=\ePtmux;\e\E[23m\e\\,

Save this and then run

tic tmux-256color-italic

and we're good to go!

All that remains is to tell tmux to use this new terminfo file, in .tmux.conf:

set-option -g default-terminal "tmux-256color-italic"

And now the italic escape codes get passed straight through tmux to the underlying terminal, meaning that we get italic text inside it.