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).
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
$TERM
in your shell (zshrc, bashrc, etc.), but your terminal (alacritty).
In ~/.config/alacritty/alacritty.yml
:
env:
TERM: xterm-256color
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"
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
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'
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
Shout-out to the nice folks that provided insightful feedback:
- @mikeslattery native neovim termguicolors support
- @mikeslattery black and white vim colorscheme
- @sahibalejandro env variable inside tmux configuration
- @wonbinbk wildcard in tmux terminal configuration
BREAKING NEWS!
(edits: I was wrong. Only the neovim changes aren't necessary.)
tl;dr - This gist is no longer necessary with latest Neovim.Neovim now checks for 256 color compatibility and automatically sets
termguicolors
.Alacritty with default$TERM
value ("alacritty") works fine. I just tested it with nightly.Recent changes announced at the Neovim conference a few days ago have made the changes in this gist unnecessary for latest builds. However, I'm sure as of this moment many people are using versions that don't yet support this and that will likely be the case for a few weeks. I don't know the exact version this was added, or which versions have it other than latest nightly.Of course, it will still be necessary for Vim.