Vim line number setting not showing when using tmux - vim

When I use vim (set number) in the .vimrc file, it works fine in the terminal, but when using tmux the line numbers just don't show.

You have to set the same $TERM for your shell and tmux. Otherwise this will cause all kinds of trouble, especially when used in connection with powerline (or vim in your case).
See: https://wiki.archlinux.org/index.php/tmux#Setting_the_correct_term

As answered by three, you have to actually set the correct $TERM for BOTH your shell and TMUX
I also had a similar problem like yours today and got it working with the following steps.
To know your current $TERM in your shell, you can use the command:
echo $TERM
for me, I got the output xterm-256color.
Then in your ~/.tmux.conf file, you can set the tmux to use xterm-256color by adding this to the file.
set -g default-terminal "xterm-256color"
and all should work fine. :)
Hope I've helped.

Related

airline.vim does not work inside tmux

I am new to tmux and also not an expert on VIM, I tried to use tmux these days, but seems that airline disappeared when I used vim inside tmux. I would like to show you the screen shots and hopefully anyone can help me solve this problem.
airline in vim
airline inside tmux
You need to correctly set $TERM environment variable to make vim properly detect 256 colors support by doing the following before opening vim:
export TERM=screen-256color
While the accepted answer works, it is not cheap. Manually setting the value of the $TERM variable will usually be set correctly by itself.
It is usually a good a idea to force tmux to assume the terminal supports 256 colors.
In your ~/.bash_aliases, add:
tmux='tmux -2'
Answer based on the following posts:
What is the difference between screen-256 color and xterm-256color
tmux vim colorscheme background is not showing
Add the following line in your .tmux.conf
set -g default-terminal screen-256color
In my case, using ubuntu 20.04 inside windows with WSL2, the accepted answer (export TERM=screen-256color), just freeze the tmux pane.
The fix for me was add to ~/.vim/vimrc:
set t_Co=256

How do I stop my VIM background from being transparent in tmux where there is no text?

I've been working on moving my development setup to a new Ubuntu based partition from Mac OS.
I'm currently having trouble getting the background to stay solid inside of tmux.
I have TERM set to xterm-256color in my .bashrc and vim works as intended outside of tmux. I have also aliased tmux to "tmux -2" and added
set -g default-terminal "screen-256color"
to my .tmux.conf.
My .vimrc contains:
set t_Co=256
set background=dark
color Tomorrow-Night
I suppose the best way to explain this is with images... Here is the intended look outside of tmux
(Tomorrow-Night colorscheme):
And here is what I am experiencing inside of tmux:
As you can see, the terminal background is bleeding through where there is no text.
Thanks!
I just tried reproducing your setup on my machine and I get a similar problem with the background.
It seems setting TERM to xterm-256color in your .bashrc overrides set -g default-terminal "screen-256color" from tmux and that causes issues. This makes sense as bash is running inside tmux and its setting override those from tmux.
You can easily verify this by running echo $TERM in bash within tmux. With your current setup it will be xterm-256color which is a no-go as Tmux explicitly requires this to be set to screen-256color.
A quickfix to verify this theory is just removing or commenting out a line in your .bashrc where you set TERM and trying things out.
A proper solution would be to have something like this .bashrc:
[ -z "$TMUX" ] && export TERM="xterm-256color"
The above line will:
set TERM to xterm-256color if bash is running standalone (no tmux)
will not override TERM if running inside tmux

Tmux does not show Vim colors properly (Ubuntu 14.04)

Searching around, I found that it might be a problem with Tmux detecting the correct terminal mode, so I placed this in my .tmux.conf:
set -g default-terminal "screen-256color"
Together with alias tmux="tmux -2" it makes some colorschemes work (badwolf for example), but not all of them (doesn't work for solarized, vividchalk and base16 for example). Since I wanted at least solarized, I installed it to gnome-terminal and to Vim. Colors show properly out of Tmux, but not in Tmux. I also set t_Co=256 (in Vim) but without success.
According to Tmux faq, there is nothing wrong with my configuration, but yet I can't get it to display properly. Any idea?
Update
To give a better understanding of the problem, below are some images.
First, Gvim (left) and Vim (right, in gnome-terminal):
Second, Vim (left, in gnome-terminal), Vim with tmux (right, also in gnome-terminal):
Credits: the code is from Princeton Algorithms course (authors: Robert Sedgewick and Kevin Wayne).
There are some steps required to solve this problem:
Install the solarized theme for gnome-terminal, found here.
Install the solarized theme for Vim (found here).
Create an alias for the tmux command or set the TERM variable as mentioned in ianks answer (in your .bashrc):
alias tmux="TERM=screen-256color-bce tmux"
Include the following line in your .tmux.conf:
set -g default-terminal "screen-256color"
I needed all these 4 steps to make my terminal colors show solarized. This post provides some other alternatives in case this doesn't work. One particular comment in that post helped the most, pointing to this resource.
It turns out that without setting the TERM variable, if you echo $TERM you see exactly what Tmux FAQ said you should (screen-256color), but you don't get the correct colors, don't know why.
Have you tried adding this to your .(*)shrc?
export TERM=screen-256color-bce
Back when I used gnome terminal this worked for me, but don't ask me why :)

Bad colorscheme in Vim running on Putty+tmux

I'm trying to set up base16-tomorrow colorscheme in my Vim, which runs on top of tmux+Putty. I exausted nearly every link on Google to get it working, but nothing happens =S
This is how the colorscheme looks like now:
How it was supposed to be:
The odd part is, no matter which base16 colorscheme I chose, it still looks the same.
Some informations about my shell:
$ echo $TERM # on Putty
xterm-256color # I configured putty to 256 colors and use this identifier
$ tmux
$ echo $TERM
screen-256color
Also, in Vim, t_Co variable is set with 256.
How can I solve this problem?
Despite having this in my .tmux.conf file, it didn't help: set -g default-terminal "screen-256color"
However, this from #xthrd helped me:
Have you tried running tmux with tmux -2 to force 256-color mode?
I had a simular issue with displaying colorschemes in tmux.
Have you tried adding set -g default-terminal "screen-256color" to your .tmux.conf

Can vim recognize when it is used in Console2?

With Steven Harman's Solarized tweak for Console2 I can more or less use the Solarized color scheme in win32 vim. But once in a while I find myself in vim via a vanilla cmd.exe window and the Solarized 16-color colorscheme is not aligned to it gui equivalent.
So I'd like to fix this inside my vimrc, but how can I check if console vim is being used in Console2?
Thanks!
In Console2, you can set arbitrary environment variables by modifying the shell invocation (from the Settings dialog, or directly in the XML config). For the default Windows command prompt, use a value of:
cmd.exe /K set EMULATOR=console2
For Cygwin Bash, something like this should work:
C:\cygwin\bin\bash.exe -c "export EMULATOR=console2; exec /bin/bash -i"
Then, check for the $EMULATOR value in a conditional in your .vimrc, as outlined by romainl's answer.
See if your terminal emulator sets an environment variable or if you can set one in one way or another.
In bash, one would do:
$ export EMULATOR=console2
With that out of the way, you can put something like this in your _vimrc:
if $EMULATOR == "console2"
colorscheme foo
else
colorscheme bar
endif

Resources