Herr Bischoff

How to Enable True Color and Italics in tmux

There are lots of different instructions floating around the internet, most of them outdated, incorrect or plain false. Even the tmux FAQ is not fully correct — tic does not read from stdin on BSD-based operating systems, including macOS. Here’s how to do it, recorded for posterity and updated when changes are necessary.

Create a file named tmux.terminfo

# tmux.terminfo

tmux|tmux terminal multiplexer,
    ritm=\E[23m, rmso=\E[27m, sitm=\E[3m, smso=\E[7m, Ms@,
    use=xterm+tmux, use=screen,

tmux-256color|tmux with 256 colors,
    use=xterm+256setaf, use=tmux,

and run

tic -x tmux.terminfo

Add to .tmux.conf

set -g default-terminal "tmux"
set-option -sa terminal-overrides ",xterm*:Tc"

Afterwards, restart your tmux session. That’s it, really. If you use tmux 2.1 or newer, that is. If you don’t, update tmux or compile from source if you only have access to ancient software packages.

This works for Linux and macOS. If you use FreeBSD, you may need to apply a terminfo patch to get the same result. Save the following as termcap.patch

--- termcap.orig	2020-08-15 23:59:02.859210000 +0200
+++ termcap	2020-08-16 00:00:36.756262000 +0200
@@ -2787,6 +2787,17 @@
 screen-256color|VT 100/ANSI X3.64 terminal with 256 colors:\
+ecma+italics|ECMA-48 italics:\
+	:ZH=\E[3m:ZR=\E[23m:
+tmux|tmux terminal multiplexer:\
+	:so=\E[7m:se=\E[27m:\
+	:tc=ecma+italics:tc=screen:
+tmux-256color|tmux with 256 colors:\
+	:so=\E[7m:se=\E[27m:\
+	:tc=ecma+italics:tc=screen-256color:
 # $XTermId: termcap,v 1.78 2009/11/09 00:24:26 tom Exp $
 # Note:
@@ -2829,7 +2840,8 @@
-	:ue=\E[24m:up=\E[A:us=\E[4m:ve=\E[?12l\E[?25h:vi=\E[?25l:vs=\E[?12;25h:
+	:ue=\E[24m:up=\E[A:us=\E[4m:ve=\E[?12l\E[?25h:vi=\E[?25l:vs=\E[?12;25h:\
+	:tc=ecma+italics:

 # The xterm-new description has all of the features, but is not completely
 # compatible with vt220.  If you are using a Sun or PC keyboard, set the

then apply and rebuild the termcap database

patch -d /usr/share/misc/ < termcap.patch
cap_mkdb /usr/share/misc/termcap

It’s in the FreeBSD source tree since December 2018, yet somehow it wasn’t present on my machines.