23

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= endif 

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?

EDIT:

My .vimrc in GitHub Gist

https://gist.github.com/sohnryang/3c63397f332f2e30c7d7b2a83c3c9f52

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

3 Answers 3

15

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.

2
  • I had the same issue. would be great to get termguicolors working on tmux though Commented Jan 26, 2017 at 11:29
  • thank you! this fixed it, I spent quite a while trying to figure this out Commented Mar 18, 2021 at 21:27
10

From the vim manual: :h termguicolors recommends reading :h xterm-true-color, also see :h $TERM

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: (nvim recommends not using &term but rather $TERM )

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 endif 
1
  • This one worked for me on NVim. Running on Arch and Fish shell Commented Apr 29, 2020 at 10:27
5

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

3
  • :syn on : colorscheme Spacegray : set termguicolors Commented May 9, 2018 at 15:33
  • In my case, it worked well without set termguicolors. Thank you, anyway! Commented Apr 19, 2020 at 5:24
  • Adding the export fixed it in my case, nice work! Commented Mar 18, 2021 at 21:29

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.