4

Just an interesting little problem I've got going on with terminals. I'm using vim inside of gnome-terminal. I like to have 256 colours so I don't have to use gVIM.

My relevant .zshrc settings are:

export TERM=xterm-256color

My relevant .vimrc settings are:

if $COLORTERM == 'gnome-terminal'
  set t_Co=256
endif

You'll notice from this showterm what the problem is: http://showterm.io/06460aeb043cac4bd0256

I'm getting a weird background colour with the tmux vim. Any help on this would be great.

b1nd
  • 370
  • 6
  • 12
  • Does the answer here help? http://stackoverflow.com/questions/10158508/lose-vim-colorscheme-in-tmux-mode?rq=1 – yanhan Dec 13 '13 at 01:55

2 Answers2

4

This is just a quick investigation.

  1. after execute tmux inside gnome-termnial, "COLORTERM" will be overwritten. That means $COLORTERM is NULL inside tmux.

The flow of these variables.

  1. gnome-terminal starts and load your .zshrc. (TERM=xterm-256color COLORTERM = gnome-terminal)
  2. tmux starts. (it overwrite COLORTERM, load its config "default-terminal" as the value of TERM)
  3. tmux load .zshrc (TERM is rewritten to "xterm-256color")
  4. Now => TERM = "xterm-256color" COLORTERM = ""
  5. vim starts => (besides your .vimrc config, t_Co is set to 256 if the term is 256 color)

The problem is that tmux support 256 color correctly only if TERM="screen-256color" instead of "xterm-256color".

Below is a solution:

First, add this to your .zshrc(I use bash syntax):

if [[ $COLORTERM == 'gnome-terminal" ]]; then
            export TERM="xterm-256color"
fi

Second, add this to your "~/.tmux.conf":

set -g default-terminal screen-256color

Last, vim settings is not needed.

Any further questions, please comment.

LotAbout
  • 707
  • 5
  • 18
  • Tmux doesn't overwrite $COLORTERM. Inside tmux, $COLORTERM still equals 'gnome-terminal'. The problem is that inside tmux, $TERM is 'xterm-256color', when it needs to be 'screen-256color'. Not sure why the .tmux.conf isn't overriding it. – b1nd Dec 14 '13 at 01:45
  • Well, my tmux overwrites it in my experiment, thanks for point this out. For the second, I believe it is because tmux load .tmux.conf first and then load .zshrc, so any further configuration in .zshrc will be finally set. – LotAbout Dec 14 '13 at 02:08
1

Try the following. This has worked for me:


.tmux.conf

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

Also, remove the old term value for .vimrc

Community
  • 1
  • 1
Kiran PS
  • 19
  • 1
  • 3