Skip to content

Instantly share code, notes, and snippets.

@andersevenrud
Last active April 23, 2025 08:47
Show Gist options
  • Save andersevenrud/015e61af2fd264371032763d4ed965b6 to your computer and use it in GitHub Desktop.
Save andersevenrud/015e61af2fd264371032763d4ed965b6 to your computer and use it in GitHub Desktop.
True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

True Color (24-bit) and italics with alacritty + tmux + vim (neovim)

This should make True Color (24-bit) and italics work in your tmux session and vim/neovim when using Alacritty (and should be compatible with any other terminal emulator, including Kitty).

Testing colors

Running this script should look the same in tmux as without.

curl -s https://gist.githubusercontent.com/lifepillar/09a44b8cf0f9397465614e622979107f/raw/24-bit-color.sh >24-bit-color.sh
bash 24-bit-color.sh

colors

Configuration files

โš ๏ธ IMPORTANT โš ๏ธ Don't set $TERM in your shell (zshrc, bashrc, etc.), but your terminal (alacritty).

Alacritty

In ~/.config/alacritty/alacritty.yml:

env:
  TERM: xterm-256color

tmux

In ~/.tmux.conf (or ~/.config/tmux/tmux.conf):

set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

# Or use a wildcard instead of forcing a default mode.
# Some users in the comments of this gist have reported that this work better.
#set -sg terminal-overrides ",*:RGB"

# You can also use the env variable set from the terminal.
# Useful if you share your configuration betweeen systems with a varying value.
#set -ag terminal-overrides ",$TERM:RGB"

vim

In ~/.vimrc:

" You might have to force true color when using regular vim inside tmux as the
" colorscheme can appear to be grayscale with "termguicolors" option enabled.
if !has('gui_running') && &term =~ '^\%(screen\|tmux\)'
  let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif

syntax on
set termguicolors
colorscheme yourfavcolorscheme

neovim

If you use ~/.vimrc for your nvim configuration, use the above vim example because it's fully compatible.

๐Ÿ’ก neovim recently (Dec 6th 2023) merged some changes that detects termguicolors automatically, so there's no need to set this in an upcoming release. I'll update this notice with a version once released as a public version. This came with the 0.10 release (May 16th 2024).

In ~/.config/nvim/init.vim

set termguicolors
colorscheme yourfavcolorscheme

Or ~/.config/nvim/init.lua:

vim.o.termguicolors = true
vim.cmd'colorscheme yourfavcolorscheme'

Not working correctly ?

Check out the comments below for possible solutions.

And if you found another solution I would really appreciate if you left a comment with instructions and the following information:

  • OS/Distro + version
  • Vim or Neovim + version
  • Terminal name + version

Mentions

Shout-out to the nice folks that provided insightful feedback:

@rnmp
Copy link

rnmp commented Apr 19, 2022

Thank you! Life saver.

@nmdra
Copy link

nmdra commented May 6, 2022

Thanks, Man, You saved my lifeโ€ฆ!!

image

@kotajacob
Copy link

Amazing! Thank you!

@harushinogen
Copy link

Thank You!

@sebastianvera
Copy link

This is what worked for me:

alacritty.yml

env:
  TERM: xterm-256color

.tmux.conf

set -g default-terminal 'xterm-256color'
set -as terminal-overrides ',xterm*:Tc:sitm=\E[3m'

Thank you!

@S1ro1
Copy link

S1ro1 commented Jun 18, 2022

This was the only thing that worked for me too, arch linux

@pipewire-debian
Copy link

@nmdra May we get your .dotfiles ?
Thank you.

@eug-L
Copy link

eug-L commented Jun 27, 2022

Thank you!!

@udithvb
Copy link

udithvb commented Jun 30, 2022

Thank you!!

@iamteem
Copy link

iamteem commented Jul 3, 2022

Thank you! ๐Ÿท

@imsuck
Copy link

imsuck commented Jul 18, 2022

Thank you!

@sahibalejandro
Copy link

I recently discovered that you can use ENV variables inside your tmux.conf so you can have something like:

set -ag terminal-overrides ",$TERM:RGB"

This is useful in the case you're sharing (like me) your tmux.conf between computers and the value of $TERM is different for each one.

@andersevenrud
Copy link
Author

@sahibalejandro That's pretty sick! I've updated the document with this information :)

@phuongthuan
Copy link

Hi guys, I was following the instruction and I hit another problem.
When I change

set -g default-terminal "screen-256color"

to

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

The problem is exactly like this: https://stackoverflow.com/questions/45931164/duplicated-characters-and-non-updating-input-using-tmux-in-zsh
I don't know why :(

@andersevenrud
Copy link
Author

@phuongthuan I haven't personally experienced this, but I would suspect that it has something to do with your configuration files related to either the shell or tmux. If you have some custom stuff there, try to start fresh with these instructions and slowly start adding your other stuff.

@tony-sol
Copy link

tony-sol commented Aug 2, 2022

Using

set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

breaks tmux in alacritty with can't find terminal definition for tmux-256color error (as well as using tmux.conf without default-terminal and terminal-overrides declarations), but fonts and color in neovim are ok, but :checkhealth says

  - WARNING: Neither Tc nor RGB capability set. True colors are disabled. 'termguicolors' won't work properly.
    - ADVICE:
      - Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:
          set-option -sa terminal-overrides ',XXX:RGB'
      - For older tmux versions use this instead:
          set-option -ga terminal-overrides ',XXX:Tc'

Using

set -g default-terminal "xterm-256color"

fixes opening tmux, neovim fonts are ok, but colors changed and :checkhealth says:

  - ERROR: $TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.
    - ADVICE:
      - Set default-terminal in ~/.tmux.conf:
          set-option -g default-terminal "screen-256color"
      - https://github.com/neovim/neovim/wiki/FAQ

Well, using

set -g default-terminal "screen-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

fixes opening tmux, fixes neovim colors and :checkhealth, but breaks neovim fonts

What a mess!

UPD: After updating ncurses by this guide, tmux-256color is finally supported and all works good

@krmckone
Copy link

krmckone commented Aug 4, 2022

Only thing that worked for me: adding set -ag terminal-overrides ",alacritty:RGB" to .tmux.conf file

macOS v12.4
NVIM v0.7.2
alacritty v0.10.1

@johanvx
Copy link

johanvx commented Aug 6, 2022

Thanks so much!

I use iTerm2 and Alacritty at the same time, and the following settings work fine on my machine.

Versions

  • macOS 13.0 Beta
  • iTerm2 3.4.16
  • alacritty 0.10.1
  • tmux 3.3a
  • NVIM 0.8.0-dev

Configurations

  • iTerm2

    Preferences -> Profiles -> Terminal
    
    Terminal Emulation
      Report terminal type: xterm-256color
    
  • Alacritty

    # ~/.config/alacritty/alacritty.yml
    env:
      TERM: xterm-256color
  • Tmux

    # .tmux.conf
    set -g default-terminal "xterm-256color"
    set -ag terminal-overrides ",xterm-256color:RGB"

@gcarlos64
Copy link

Tried all the things but nothing works

OS: Voidlinux
Alacritty: 0.10.1
Tmux: 3.3a

@wonbinbk
Copy link

wonbinbk commented Aug 27, 2022

I followed all your instructions but still in tmux it couldn't display 24-bit color.
However, just by luck I found another guide and the only difference is in this:

set -ag terminal-overrides ",xterm-256color:RGB" -> set -sg terminal-overrides ",*:RGB"

And there we go, I have 24-bit color in tmux.

@fiskhest
Copy link

fiskhest commented Sep 1, 2022

I followed all your instructions but still in tmux it couldn't display 24-bit color. However, just by luck I found another guide and the only difference is in this:

set -ag terminal-overrides ",xterm-256color:RGB" -> set -sg terminal-overrides ",*:RGB"

And there we go, I have 24-bit color in tmux.

Same here on arch linux with latest tmux and alacritty. I tried every suggestion in this thread but only after setting set -sg terminal-overrides ",*:RGB" and restarting the tmux server I had true 24b support.

@EriKWDev
Copy link

If you have nvim installed, you can open it and type the command :checkhealth and it will give some debugging tips for tmux colors as well

@wangyandongnx
Copy link

Thanks so much!

I use iTerm2 and Alacritty at the same time, and the following settings work fine on my machine.

Versions

  • macOS 13.0 Beta
  • iTerm2 3.4.16
  • alacritty 0.10.1
  • tmux 3.3a
  • NVIM 0.8.0-dev

Configurations

  • iTerm2
    Preferences -> Profiles -> Terminal
    
    Terminal Emulation
      Report terminal type: xterm-256color
    
  • Alacritty
    # ~/.config/alacritty/alacritty.yml
    env:
      TERM: xterm-256color
  • Tmux
    # .tmux.conf
    set -g default-terminal "xterm-256color"
    set -ag terminal-overrides ",xterm-256color:RGB"

Thanks! It works for me.

@Mohamed-Ibrahim-01
Copy link

Thank you so much, finally it worked ๐ŸŽ‰

This line from the comments helped also set -sg terminal-overrides ",*:RGB"

@andersevenrud
Copy link
Author

andersevenrud commented Oct 7, 2022

@wonbinbk I've added your solution to this document as it seems other users have success in using this as well.

Haven't been able to reproduce the issues with original instructions even on the same systems as reported, but it seems like this area is filled with dragons ๐Ÿ˜…

Thanks!

@tobias-edwards
Copy link

tobias-edwards commented Nov 23, 2022

This is what worked for me:

alacritty.yml

env:
  TERM: xterm-256color

.tmux.conf

set -g default-terminal 'xterm-256color'
set -as terminal-overrides ',xterm*:Tc:sitm=\E[3m'

Thank you!

Almost worked perfectly but the terminal override inappropriately rendered \E[3m characters in Neovim, so I ended up fiddling and tweaking using these guides until colours, symbols, bold, italics all worked for me:

@p1xelHer0
Copy link

p1xelHer0 commented Nov 23, 2022

This is what worked for me:

alacritty.yml

env:
  TERM: xterm-256color

.tmux.conf

set -g default-terminal 'xterm-256color'
set -as terminal-overrides ',xterm*:Tc:sitm=\E[3m'

Thank you!

This worked for me as well, thanks!

- macOS Monterey @ 12.6.1
- Alacritty      @ 0.11.0
- tmux           @ 3.3a

@matheustanaka
Copy link

I followed all your instructions but still in tmux it couldn't display 24-bit color. However, just by luck I found another guide and the only difference is in this:

set -ag terminal-overrides ",xterm-256color:RGB" -> set -sg terminal-overrides ",*:RGB"

And there we go, I have 24-bit color in tmux.

Thanks for that solution!
I'm using pop os with alacritty neovim and tmux, but when I installed tmux, my colors on neovim broken. After put set -sg terminal-overrides ",*:RGB" everything works again.

@mikeslattery
Copy link

ssh does not work correctly for one of my other desktops, probably because tmux-256color is unknown to it. I had to SetEnv to my ~/.ssh/config. There might be a better way, but this works well.

Host otherdesktop
  Hostname otherdesktop
  SetEnv TERM=xterm

Ad-hoc alternate: TERM=xterm ssh otherdesktop

@anaetrezve
Copy link

Works like charm. Thank you so much

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