tmux - vim colorscheme is off

t3kg33k

New Member
Joined
Oct 7, 2022
Messages
14
Reaction score
6
Credits
161
I am hoping someone can assist with my conundrum.
I have tmux and VIM setup as such on my local profile:

.tmux.conf
Code:
set -g default-terminal "xterm-256color"

.vimrc
Code:
set term=xterm-256color
colorscheme ron

While in a tmux session, I ssh to a remote machine as a standard user and VIM uses the default colorscheme but the tmux session looks horrible with red text that is a bit overbearing to me. Of course, the same is seen if I switch to root on the remote machine. This only happens in while in a tmux session.

screenshot tmux session on remote machine
Screenshot_20251008_101643.png


screenshot non-tmux session on remote machine
Screenshot_20251008_101715.png


It looks as if tmux session on the remote machine is still using xterm-256color
Screenshot_20251008_102608.png


Can anyone explain this behavior of the red text in VIM on a tmux session and how to fix it?
Thanks.
 

Attachments

  • Screenshot_20251008_101348.png
    Screenshot_20251008_101348.png
    36.5 KB · Views: 186


I am hoping someone can assist with my conundrum.
I have tmux and VIM setup as such on my local profile:

.tmux.conf
Code:
set -g default-terminal "xterm-256color"

.vimrc
Code:
set term=xterm-256color
colorscheme ron

While in a tmux session, I ssh to a remote machine as a standard user and VIM uses the default colorscheme but the tmux session looks horrible with red text that is a bit overbearing to me. Of course, the same is seen if I switch to root on the remote machine. This only happens in while in a tmux session.


Can anyone explain this behavior of the red text in VIM on a tmux session and how to fix it?
Thanks.
There's a few issues here to consider.

Having set xterm-256color in the .tmux.conf file may be a confounding variable because you are asking the terminal in tmux to control the color of an xterm instead of just letting X do it, or asking X to do it or letting tmux use X. Tmux by default uses it's own terminal which is not xterm. With vim there may also be some confounding by unnecessarily asking vim to use a particular terminal about color instead of X.

The behaviour you describe is not present on a machine here which has different configurations as outlined below.

The terminal here is xterm:
Code:
echo $TERM
xterm

Modern X is usually configured to run color. One can check that by having a look at the file:
/etc/X11/Xresources/x11-common. If that file exists and has the config: *customization: -color, then X is set to use color and one doesn't need to configure the xterm-256color. One can set the same config in a
/home/$USER dotfile like .Xdefaults, or .Xresources to tell X to use color if it otherwise has the capability and is not set elsewhere. That color usage will include using color for xterm.

For vim to show color, as in the examples in post #1, one only needs to set the config in the .vimrc file as: syntax on rather than setting the terminal in its configs. Again one leaves the general setting of color to X and let vim run it's own defaults in its syntax config.

The tmux config file on the machine here that runs tmux doesn't set a terminal config in the
/home/$USER/.tmux.conf file, but uses the default tmux terminal which shows as follows:
Code:
[~]$ echo $TERM
tmux-256color
The modern tmux terminal has color covered. The colors I've found here in the tmux machine are basically the same colors one expects when using xterm outside of tmux, and also for vim and other apps inside or outside tmux. It may be the case that the configs described in post #1 were used for earlier versions of tmux which are now superfluous or redundant and actually part of the issue you are seeing. YMMV
 
Last edited:
Thanks for that information. I really appreciate it.
Question: What if the local and remote machines aren't using XServer but Wayland insead?
Also, if I don't set a default terminal in my .tmux.conf, the terminal is set to screen. And also setting no terminal or colorscheme in .vimrc really ensures I see red text every time in VIM, which is something I am trying to avoid.
I guess there no easy solution for this? That I will just have to manually enter a colorscheme that doesn't display red text every time I use VIM in a tmux session?
 
Thanks for that information. I really appreciate it.
Question: What if the local and remote machines aren't using XServer but Wayland insead?
Also, if I don't set a default terminal in my .tmux.conf, the terminal is set to screen. And also setting no terminal or colorscheme in .vimrc really ensures I see red text every time in VIM, which is something I am trying to avoid.
I guess there no easy solution for this? That I will just have to manually enter a colorscheme that doesn't display red text every time I use VIM in a tmux session?
On wayland, I can't say not having used it yet, so it's all X here.

On the colors in vim, as you mention, the colorscheme configurations are available to set. To be clear on that, here is an example in a file that has colors from the syntax config. After going to command mode I write:
Code:
:colorscheme <space> <ctrl+d>
where <space> means to hit the space bar, and <ctrl+d> means to hit the ctrl key with the d key.
Then a menu of color schemes should appear like this in the file:
Code:
<snip>
 38 # printf '%s\n' "$*" --- print all args with newline
 39 # set +f --- enable file name generation (globbing)
 40
 41
 42
 ~                                                               
~
<snip>                                                               
testfile                                       1,1            All
:colorscheme
blue        evening     murphy      shine       zaibatsu
darkblue    habamax     pablo       slate       zellner
default     industry    peachpuff   sorbet
delek       koehler     quiet       torte
desert      lunaperche  retrobox    unokai
elflord     morning     ron         wildcharm
:colorscheme
Then the :colorscheme config becomes available to select one of the themes from the theme names presented. After one is selected, I press the enter key and the color theme will apply to the file. For example: :colorscheme wildcharm. If I wanted the theme to apply universally, it can be configured it in the .vimrc. One can actually create one's own color scheme if it comes down to that, but I've not ventured there.

On this finding you mention:
I don't set a default terminal in my .tmux.conf, the terminal is set to screen
it's not the case here with tmux version 3.5a-3. As shown in post #2, the default tmux terminal appears. Perhaps have a look at the tmux example in the tmux docs and see if it's any help, here:
/usr/share/doc/tmux/example_tmux.conf.
 
Thanks again for the response and information.
Yeah, I use the colorscheme within VIM to ensure my preference.
Unfortunately, the machines I am required to use at work where I am trying to get some consistency across all my tmux sessions are all RHEL 8 based and the latest tmux version is 2.7.
Thanks again. I'll just have to continue as I have for so long of just manually setting a viewable colorscheme in my tmux sessions.
 


Follow Linux.org

Members online


Top