Color scheme of a nested terminal, tmux, ssh, vim setup
Asked Answered
S

1

7

On my local computer, iterm terminal contains tmux. Inside tmux, there is ssh remote connection. In this remote connection, I run tmux in server side. Inside that tmux, I run vim.

So, the container relationship is the following: First iterm, then tmux, then ssh remote connection, then tmux, then vim.

Now, how are the colors of vim determined? Which color scheme of which application is effective?

Saber answered 13/9, 2014 at 8:32 Comment(0)
F
10

The colors you see are, in fine, limited by the "physical" capabilities of your terminal emulator but their number is generally altered by the TERM environment variable that is used by programs to determine how fancy they can be in their coloring.

In simplistic terms…

  • when Vim checks your TERM and sees a value containing 256, it assumes your terminal emulator is capable of displaying 256 colors and acts accordingly.

  • when your TERM is xterm or screen (among others), Vim assumes your terminal emulator is only capable of displaying 8 colors and acts accordingly.

Assuming your current TERM in your local terminal emulator is xterm-256color and none of the intermediary *rc sets a specific TERM:

WHERE                                 TERM              COLORS
--------------------------------------------------------------
local                                 xterm-256color    256
local > vim                           xterm-256color    256
local > remote                        xterm-256color    256
local > remote > vim                  xterm-256color    256
local > remote > remote > remote > remote > remote > remote >
> remote > remote > remote > remote   xterm-256color    256
local > remote > tmux                 screen            8
local > remote > tmux > vim           screen            8
local > tmux                          screen            8
local > tmux > vim                    screen            8
local > tmux > remote                 screen            8
local > tmux > remote > tmux          screen            8
local > tmux > remote > tmux > vim    screen            8

Tmux, as a terminal multiplexer, acts as if it was a terminal emulator and changes your TERM to tmux's default value, screen, and that new value is what is passed down along the chain.

If you want tmux and fancy colors everywhere, you need to configure each tmux to use a 256 colors-ready TERM. Put this line in ~/.tmux.conf on every machine you log in, including yours:

set-option -g default-terminal "screen-256color"
Flaunt answered 13/9, 2014 at 13:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.