I installed tmux in iTerm 2.(Build 3.0.13) When I execute vim in tmux, syntax highlighting looks like this.

no syntax highlighting

But outside tmux, syntax highlighting looks fine.

ordinary syntax highlighting

My $TERM inside and outside tmux is xterm-256color. I also added

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

in .tmux.conf and added this

set t_Co=256
set t_AB=m
set t_AF=m
if &term =~ '256color'
    set t_ut=

in .vimrc.

I also tried tmux -2 command and read these questions.

lose vim colorscheme in tmux mode

Incorrect colors with vim in iTerm2 using Solarized

Is this a problem of tmux, vim, or my configuration?


My .vimrc in GitHub Gist


  • What will happen when you start your tmux with -2 option: tmux -2. Preferably when there are no sessions in tmux. – grodzik Dec 22 '16 at 14:17
  • I used tmux -2, but the problem is same. – sohnryang Dec 22 '16 at 14:17
  • Could you share whole .vimrc? – grodzik Dec 22 '16 at 18:25
  • 1
    @sohnryang what part of "maybe you shouldn't" do you not understand? – muru Dec 26 '16 at 10:02
  • 1
    Try following these steps. You have a whole lot of plugins so perhaps one of those is interfering. – Martin Tournoij Dec 31 '16 at 3:49

Well, I solved the problem by myself.

as @Carpetsmoker♦ commented, I started to suspect that my .vimrc is a problem. I read this question and started vim with this command inside tmux.

vim -u NONE -U NONE -N ~/.vimrc

After starting vim with command above, I ran this command inside vim.

:syn on
:colorscheme solarized8_dark

These highlighted my .vimrc file. So, I started to debug my .vimrc.

Long story short, set termguicolors was the problem. If I ran vim with set termguicolors commented in .vimrc, I could see corrected syntax highlighting in tmux.

  • I had the same issue. would be great to get termguicolors working on tmux though – Filype Jan 26 '17 at 11:29

I actually made it work just fine with termguicolors. This is what I did 1. in my ~/.bash_profile i put this:

export TERM=xterm-256color

and inside my ~/.vimrc I had this

syntax enable
colorscheme Spacegray

set termguicolors

and it worked perfectly! reference

  • :syn on : colorscheme Spacegray : set termguicolors – abbood May 9 '18 at 15:33

From the vim manual: :h termguicolors recommends reading :h xterm-true-color

Sometimes setting 'termguicolors' is not enough and one has to set the |t_8f|
and |t_8b| options explicitly.  [ ... these are]  only set [to some default] when `$TERM` is `xterm`.

I use a condition similar to the below:

if &term =~# '256color' && ( &term =~# '^screen'  || &term =~# '^tmux' )
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
    set termguicolors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.