Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors are off when running Vim via SSH inside tmux. #4

Closed
paddor opened this issue Oct 12, 2016 · 18 comments
Closed

Colors are off when running Vim via SSH inside tmux. #4

paddor opened this issue Oct 12, 2016 · 18 comments

Comments

@paddor
Copy link
Contributor

paddor commented Oct 12, 2016

I'm using iTerm2 3.0.10 on macOS which connects via SSH to an Ubuntu 14.04 VM running Neovim 0.1.6-dev and Tmux 2.0.

I have the following vim config:

packadd vim-solarized8
colorscheme solarized8_dark
set t_8f=^[[38;2;%lu;%lu;%lum
set t_8b=^[[48;2;%lu;%lu;%lum
set termguicolors

(the ^[ are actual escape sequences)

This works pretty well without Tmux, like this:
screen shot 2016-10-12 at 21 43 34

But as soon as I start nvim inside Tmux, it looks FUCKED. Like this:

screen shot 2016-10-12 at 21 41 29

My TERM is xterm-256color outside of tmux, and screen-256color inside.

I've tried pretty much "everything" but no success. Any ideas why?

@lifepillar
Copy link
Owner

I cannot reproduce that, at least using Vim (I don't have NeoVim in the Ubuntu box I'm connecting to). My Vim configuration is like yours. It sounds like a tmux problem.

This is the terminal configuration in my .tmux.conf, in case it helps:

set -g  default-terminal            "tmux-256color"
set -ga terminal-overrides          ",xterm-256color:Tc"

(I set the terminal to tmux-256color rather than screen-256color because I have custom terminfo files in my home directory).

@lifepillar
Copy link
Owner

This is a comment from my personal dotfiles repository, when I introduced the lines above:

Setting terminal-overrides seems to be necessary to enable true colors within tmux.

@paddor
Copy link
Contributor Author

paddor commented Oct 13, 2016

Thanks for the help. Unfortunately adding the two lines (with screen-256color) didn't help. What kind of custom terminfo files do you have there?

@lifepillar
Copy link
Owner

lifepillar commented Oct 13, 2016

From ncurses.

brew install ncurses
mkdir -p ~/.terminfo/{74,78}
cp /usr/local/opt/ncurses/share/terminfo/74/tmux-256color ~/.terminfo/74
cp /usr/local/opt/ncurses/share/terminfo/78/xterm-256color ~/.terminfo/78

They give me italics in terminal (also in Terminal.app).

@lifepillar
Copy link
Owner

Ah, in Ubuntu you should put tmux-256color into ~/.terminfo/t/, not ~/.terminfo/74.

@lifepillar
Copy link
Owner

Btw, I'm using tmux 2.1, if that matters.

@paddor
Copy link
Contributor Author

paddor commented Oct 14, 2016

I managed to upgrade to Tmux 2.4 (prerelease I guess?) but I can't easily upgrade ncurses-base to get that tmux-256color file. :( And the xterm one doesn't help either.

@lifepillar
Copy link
Owner

This is the content of my ~/.terminfo/t/tmux-256color:

tmux-256color|tmux with 256 colors,
        am, hs, km, mir, msgr, xenl,
        colors#256, cols#80, it#8, lines#24, pairs#32767,
        acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
        clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM,
        cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
        dl=\E[%p1%dM, dl1=\E[M, dsl=\E]0;\007, ed=\E[J, el=\E[K,
        el1=\E[1K, enacs=\E(B\E)0, flash=\Eg, fsl=^G, home=\E[H,
        ht=^I, hts=\EH, ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L,
        ind=^J, is2=\E)0, kbs=^H, kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB,
        kcuf1=\EOC, kcuu1=\EOA, kdch1=\E[3~, kend=\E[4~, kf1=\EOP,
        kf10=\E[21~, kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR,
        kf4=\EOS, kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~,
        kf9=\E[20~, khome=\E[1~, kich1=\E[2~, kmous=\E[M,
        knp=\E[6~, kpp=\E[5~, nel=\EE, op=\E[39;49m, rc=\E8,
        rev=\E[7m, ri=\EM, ritm=\E[23m, rmacs=^O, rmcup=\E[?1049l,
        rmir=\E[4l, rmkx=\E[?1l\E>, rmso=\E[27m, rmul=\E[24m,
        rs2=\Ec\E[?1000l\E[?25h, sc=\E7,
        setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
        setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
        sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p5%t;2%;m%?%p9%t\016%e\017%;,
        sgr0=\E[m\017, sitm=\E[3m, smacs=^N, smcup=\E[?1049h,
        smir=\E[4h, smkx=\E[?1h\E=, smso=\E[7m, smul=\E[4m,
        tbc=\E[3g, tsl=\E]0;,

@paddor
Copy link
Contributor Author

paddor commented Oct 15, 2016

I upgraded to Ubuntu LTS 16.04 and downgraded tmux to 2.1 and now it kinda works (using screen-256colors terminfo). I have more normal colors, but for some reason, the background is kinda brown? See here:

screen shot 2016-10-15 at 01 54 57

It's like that even if I comment those few hi lines out. Are your solarized colors by any chance based on ajacksified/vim-colors-solarized-brown?

I prefer the green-ish background.

Oh and thanks for your tmux-256color! Same problem with it though.

@lifepillar
Copy link
Owner

Are your solarized colors by any chance based on ajacksified/vim-colors-solarized-brown?

No, the color palette is from the original Solarized.

Oh and thanks for your tmux-256color! Same problem with it though.

You may try raising an issue at the tmux repository. I am afraid I have run out of ideas :(

@paddor
Copy link
Contributor Author

paddor commented Oct 17, 2016

I might do that. Thanks anyway for your help!

@paddor paddor closed this as completed Oct 17, 2016
@frioux
Copy link

frioux commented Jul 1, 2017

FWIW I have the same issue

@lifepillar
Copy link
Owner

Reopening, because I can now reproduce the issue.

Let me summarise the problem: the issue here is that Vim colors do not look right when

  1. you connect to a remote (Ubuntu) box via SSH;
  2. you run a tmux session in the remote box;
  3. you run an instance of Vim or NeoVim in the remote box, with termguicolors on, and t_8f and t_8b explicitly set.

Besides, your local terminal does support true colors (e.g., iTerm2). The local terminal color palette should not matter. Finally, if you run Vim outside tmux, colors do look fine.

What I have found is that there seems to be a problem with true colors in tmux, which is independent of Vim. To verify that, can you please try the following script both inside and outside tmux?

#!/bin/bash
#
# https://gist.github.com/XVilka/8346728
#
awk 'BEGIN{
    s="/\\/\\/\\/\\/\\"; s=s s s s s s s s;
    for (colnum = 0; colnum<77; colnum++) {
        r = 255-(colnum*255/76);
        g = (colnum*510/76);
        b = (colnum*255/76);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum+1,1);
    }
    printf "\n";
}'

This is what I get outside tmux:

outside-tmux

And this is what I get inside tmux:

inside-tmux

The commands are run in the remote box, of course. I am using tmux 2.1 in Ubuntu.

@lifepillar lifepillar reopened this Jul 2, 2017
@lifepillar lifepillar changed the title All orange within tmux, otherwise good Colors are off when running Vim via SSH inside tmux. Jul 2, 2017
@frioux
Copy link

frioux commented Jul 2, 2017

Yeah, I agree and was having the same problem with that exact script in tmux. I am sorta confused because it... went away after a reboot? For more details, read here: tmux/tmux#993

@lifepillar
Copy link
Owner

This discussion seems relevant: tmux/tmux#622. If you use NeoVim, could you try what is suggested in vim-one's Readme?

@lifepillar
Copy link
Owner

I have updated tmux to v2.5 and the issue is gone. Feel free to reopen this if you still have problems with the latest tmux.

@rieger-jared
Copy link

I had this issue as well running tmux 3+. Adding the lines suggested in vim one worked for me.

# Add truecolor support
set-option -ga terminal-overrides ",xterm-256color:Tc"
# Default terminal is 256 colors
set -g default-terminal "screen-256color"

@Hrjfi
Copy link

Hrjfi commented Mar 7, 2024

Mantri Mall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants