Hacker News new | ask | show | jobs
by ndmrs 3731 days ago
I love tmux but it appears to be messing with my terminal colors for some reason, especially in vim and after enabling 256 color mode.(Also the line numbers in vim appears to be bold in tmux when they aren't if run directly from the terminal, weird.)
3 comments

You may have hit the difference between what a terminal is capable of, versus what it's actually capable of. Most modern terminals can do all kinds of fancy things like mouse-support and 256-colour output, but they advertise themselves as 1990s-era 8-colour devices for compatibility reasons. Specifically, they set $TERM to "xterm" or similar.

tmux is two kinds of terminal application: it interacts with your outer, "real" terminal, and it presents an inner, "fake" terminal to the programs running inside it. By default, tmux will respect the limitations implied by $TERM, so if your outer terminal claims to be an 8-colour device, tmux will filter the colours of applications inside it to fit the standard 8-colour palette.

Vim also respects the limitations implied by $TERM, but some people override it into using 256-colour mode anyway, by doing something like "set t_Co=256" in their .vimrc. That works for Vim running in the outer terminal, but it doesn't work for any other tools running in the outer terminal, and in particular it doesn't help tmux.

These days, it's generally best to configure your terminal app to set $TERM to something like "xterm-256color", "nsterm-256color" (for Terminal.app), "putty-256color" (for PuTTY), "gnome-256color" (for libvte-based emulators) or similar. If your terminal application doesn't support manually overriding $TERM, you can do it in your shell profile. That way, every app should understand your terminal's capabilities, including 256-colour support, both inside and outside of tmux.

Tmux recently merged a PR adding 24-bit colour, I'm a lot happier with the colours now. I think it will be in the next release if it's not out already.

https://github.com/tmux/tmux/pull/112

A couple of potential fixes:

  # Force tmux to assume the terminal supports 256 colors
  tmux -2 

  # if /usr/share/terminfo/x/xterm-256color exists
  export TERM='xterm-256color'
  # otherwise
  export TERM='xterm-color'