Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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"

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.

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
@ethmtrgt
Copy link

ethmtrgt commented Nov 24, 2021

Thank you!

@Hunter522
Copy link

Hunter522 commented Dec 7, 2021

Thanks for this. This was the only thing that worked for me. I'm thinking it was mostly the forcing the TERM variable in the alacritty.yml config.

@fhabib229
Copy link

fhabib229 commented Dec 17, 2021

This is great thank you. I had to modify my .tmux.conf file to instead include:

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

@mikeslattery
Copy link

mikeslattery commented Dec 22, 2021

If vim goes to black and white when setting termguicolors, you may need to add this:

let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"

This isn't a problem with neovim.

@andersevenrud
Copy link
Author

andersevenrud commented Dec 22, 2021

@mikeslattery Thanks! I was able to reproduce this. Updated the gist with information :)

@oxodao
Copy link

oxodao commented Jan 3, 2022

THANK YOU. I've tried making this work for years in termite, then alacritty and this FINALLY WORKS.

@mikeslattery
Copy link

mikeslattery commented Jan 3, 2022

@andersevenrud , @oxodao I'm glad to help in my small way.

I think this could make a useful dual (n)vim/tmux plugin (a la vim-tmux-navigator), esp if it were verified to work with other popular combinations (e.g. iterm2, gVim).

@xlsama
Copy link

xlsama commented Jan 20, 2022

Thank you!

@chiendo97
Copy link

chiendo97 commented Feb 16, 2022

Thank you!

@bkachinthay
Copy link

bkachinthay commented Feb 18, 2022

Thanks!

@kaiguogit
Copy link

kaiguogit commented Feb 20, 2022

Thank you very much.

@sittim
Copy link

sittim commented Feb 22, 2022

My home brew updated the terminal to Version 0.10.1 and it stopped working :(

@melkster
Copy link

melkster commented Feb 23, 2022

Thank you! TERM: xterm-256color was the last piece to the puzzle for me to get it to work properly!

@guilhermehto
Copy link

guilhermehto commented Mar 7, 2022

Thanks g!

@orafaelfragoso
Copy link

orafaelfragoso commented Mar 11, 2022

I'm using Lunar Vim + NeoVim and it's not working for Lunar.
If I open nvim it works, but not lvim.

@mjcc30
Copy link

mjcc30 commented Mar 23, 2022

I'm using Lunar Vim + NeoVim and it's not working for Lunar. If I open nvim it works, but not lvim.

same for me

@mikeslattery
Copy link

mikeslattery commented Mar 23, 2022

@mjcc30 @orafaelfragoso LunarVim config is kept in a different directory. Read LunarVim's docs. You can't expect OP to support LunarVim, btw.

@Rafaelsalass
Copy link

Rafaelsalass commented Mar 24, 2022

I had to set it to

set -g default-terminal "alacritty"
set -ag terminal-overrides ",alacritty:RGB"

OS: macos
Terminal: alacritty
Neovim

@creep33
Copy link

creep33 commented Apr 7, 2022

Thanks!

@sahibalejandro
Copy link

sahibalejandro commented Apr 13, 2022

The only thing I needed to do was to add set -ag terminal-overrides ",alacritty:RGB" to my .tmux.conf file, nothing else.

macOS v12.3.1
NVIM v0.6.1
alacritty v0.10.1

@mikeslattery
Copy link

mikeslattery commented Apr 13, 2022

@sahibalejandro I am guessing that works with Neovim but not Vim.

My experience with Neovim is that more things like this "just work"(tm). Personally, I'm sticking with the original config here as other true-color terminal apps I may install (if any) will be more likely to behave correctly.

@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

kotajacob commented May 6, 2022

Amazing! Thank you!

@harushinogen
Copy link

harushinogen commented May 15, 2022

Thank You!

@sebastianvera
Copy link

sebastianvera commented Jun 5, 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!

@S1ro1
Copy link

S1ro1 commented Jun 18, 2022

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

@pipewire-debian
Copy link

pipewire-debian commented Jun 21, 2022

@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!!

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