I am unable to get tmux to work with 256 colors and I am at a complete loss as to why it doesn’t work. To this end I have constructed a minimal reproducer that can be used with nixos-shell
{ config, lib, pkgs, ... }: {
# just so that I don't have to download another kernel
boot.kernelPackages = pkgs.linuxPackages_latest;
virtualisation.graphics = true;
nixos-shell.mounts = {
mountHome = false;
mountNixProfile = false;
};
services.xserver = {
enable = true;
desktopManager.xterm.enable = true;
displayManager.startx.enable = true;
};
programs.tmux = {
enable = true;
terminal = "tmux-256color";
extraConfig = ''
set-option -ga terminal-overrides ",*256col*:Tc:RGB"
'';
};
environment.systemPackages = [
(pkgs.neovim.override {
configure.customRC = ''
set termguicolors
'';
})
];
}
After starting up the VM, log in as root (no password) and run startx to start the X server. A few xterm windows should pop up. Now you can run nvim /etc/bashrc with and without tmux and compare the output. Here is a screenshot, left is inside tmux, right is outside.
One thing that is tricky about tmux configuration is that it won’t reload its configuration if a session is still running, so make sure you killall tmux between changes.
There are no changes being made here. All the config files are already there when the VM starts up, i.e. there is no running session. Yet it doesn’t work.
To make sure that this is not an effect my problematic setup, I’ve downloaded the latest NixOS 21.05 Live CD (iso download link) and booted it in QEMU:
The colors are clearly not the same and the left (inside tmux) is pretty unreadable. I don’t understand what is going on and why this is happening. Please help!
I just setup the same VM as you did, except my config was a bit leaner than yours:
# .tmux.conf
set-option -g default-terminal "screen-256color"
# .vimrc
syntax on
I checked the colors without vim with this bashscript[via] and the output seems to be ok in both cases (tmux and no tmux).
I checked the colors within vim with :runtime syntax/colortest.vim and they seem to work correctly in both cases.
I checked with different terminal emulators: konsole, lxterminal, lxqt.qterminal they render the color in the same way whether vim is started within tmux or not, but differ between terminals.
If you add you favorite vim colorscheme to your .vimrc the output is identical in both cases: nested in tmux or not
:colorscheme desert
so it seems like it’s a special configuration adaption for the gnome terminal. still strange why nvim chooses a different default colorscheme whether it’s started in tmux or not…
digging though the neovim issues it seems like the background-color is not detected correctly: if you issue :se bg the nvim nested in tmux outputs background=dark, nvim started directly in gnome terminal outputs background=light. via #14058