Why do Vim colors look different inside and outside of tmux?

I had the similar issue before. Comments in blue in Vim were hard to read. In .tmux.conf I set this:

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

And in .vimrc:

set background=dark

Now it looks as follows and works both in Gnome Terminal and Cygwin: enter image description here


tmux doesn't support the terminfo capability bce (back color erase), which vim checks for, to decide whether to use its "default color" scheme.

That characteristic of tmux has been mentioned a few times -

  • Reset background to transparent with tmux?
  • Clear to end of line uses the wrong background color in tmux

Thanks to @egmont's analysis of what colors Vim was outputting when TERM=screen-256color, I was inspired to look at the color scheme Vim is using in the two scenarios.

Vim reports it is using the default color scheme in both cases. I thought that odd because the default color scheme on Fedora 25 (/usr/share/vim/vim80/colors/default.vim) doesn't appear to match the colors I actually see when TERM=xterm-256color. If I explicitly set the color scheme using :colorscheme default when TERM=xterm-256color, Vim's appearance changes to that when TERM=screen-256color. To get the colors back to what they were when I first start Vim, I had to use the ron color scheme. Progress!

I found an Ask Ubuntu answer that suggests that when Vim reports it is using the default color scheme, it doesn't necessarily mean default.vim but rather some theme-specific color scheme. As the answer points out, a dark theme (which I am using) corresponds to the ron color scheme, just as I discovered above. (Even though this post is with respect to Ubuntu, I'm assuming the OP was using GNOME.)

I also found another question that seems to describe the same problem I'm having. I came across it while searching before I posted this question, but, for some reason, the color scheme didn't strike me as being relevant.

I ended up doing what @LapshinDmitry did in his answer and explicitly set colorscheme ron in my ~/.vimrc file. Now, whether I start Vim inside or outside of tmux, the colors appear the same. The only drawback is if I ever change my desktop theme from a dark flavor to a light flavor, Vim won't automatically switch to the "default" light theme color scheme, which is apparently peachpuff. I can live with that, as I'm unlikely to ever change my theme.

I'm not going to accept this answer because I consider explicitly setting the color scheme in my ~/.vimrc a workaround rather than the solution. If someone can explain why Vim loads a different "default" color scheme depending on the value of TERM, I'll be happy to accept that answer, as I'm more interested in understanding the root cause. I suspect it has something to do with how Vim interprets the terminal capabilities between the two terminfo files.