Make italics and Ctrl+h work in neovim inside tmux


I finally got italics and Ctrl+h working in neovim inside tmux. This took so much longer than it should… Posting it here in case it help someone else to get up and running faster.

If anyone else is trying to get italics working inside tmux and you have python installed via anaconda, it is enough just to change the default terminal line in ~/.tmux.conf to set -g default-terminal "tmux-256color". The terminfo file will be loaded from ~/anaconda3/terminfo/t/tmux-256-color. None of the other suggested solutions worked for me, I suspect the anaconda setup just overwrites any modifications done manually with via tic.

Ctrl + h

This fixes italics, but does not fix the ^h issue. However, for my purposes (navigating tmux panes), this can be taken care of by adding nmap <BS> :TmuxNavigateLeft<CR> to ~/.config/neovim/init.vim, since ctrl+h incorrectly sends the backspace key (this issue will be fixed in the next neovim release).

True colors

This one didn’t take as long, but I still would not call it intuitive. First, tmux -V need to output at least 2.2. Then add the folowing to ~/.tmux.conf

# Add truecolor support for the terminals you use
set-option -ga terminal-overrides ",xterm-256color:Tc,screen-256color:Tc,tmux-256color:Tc"
# Default terminal is 256 colors
set -g default-terminal "tmux-256color"

Test it by running this both outside and inside tmux

awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    printf "\n";

The color bar gradient should be smooth and look like in the rightmost image here. Now add set termguicolors to ~/.config/neovim/init.vim. That’s it!

Post-doctoral teaching fellow

Developmental biology researcher and data science educator