First off:
I'm using tmux 2.5 installed via homebrew on OS X 10.12, in iTerm 2 (though the problem appears in Terminal.app as well). My tmux.conf is on Github, along with my zshrc.
The problem: Seemingly out of nowhere, I started seeing an issue with typing in the prompt. Typing keys once will display them twice, and backspacing will move the cursor forward and redraw characters already present on the line. This only happens inside of a tmux session, and not inside my "regular" terminal.
Here's a gif of the issue. In this gif, I type 1234567890, then hit backspace 9 times, and type ls. Note that 0 only shows up once, and lls with a duplicated l runs the ls command as expected.
Hopefully I just hit a weird key combo on accident, but I've been stuck on this for a while.
Thanks for any help!
Installing tmux-256color for macOS as in this guide solves the problem.
Running the following as mentioned in a github issue solved the problem for me:
brew install ncurses
$(brew --prefix)/opt/ncurses/bin/infocmp tmux-256color > ~/tmux-256color.info
tic -xe tmux-256color tmux-256color.info
infocmp tmux-256color | head
I'm also running into this issue as well. I encountered the problem similar to #artemave, by trying to change the set -g default-terminal "screen-256color" to set -g default-terminal "tmux-256color". The goal of doing this was to gain italics, per the tmux FAQ.
#taylor's answer didn't work for me, as I didn't have that command.
I managed to determine that:
The issue doesn't occur with bash
When running a blank .zshrc, backspacing creates new blank lines, but I'm not seeing the character duplication
Using tmux-256color will successfully give italic fonts
Using TERM=xterm-256color and TERM=konsole-256color does not change the above effects
Using xfce4terminal (0.8.9.1), Konsole (19.12.3), or URXVT (9.22) doesn't change the above behavior
I wasn't able to really "fix" the issue, as the even going down to a blank .tmux.conf wasn't able to change anything. Instead, I just needed to change it to anything else. xterm-256color was suggested in this issue, but I found nearly anything else would work fine.
I'll keep working on it and update this answer if I find anything else.
Edit: This tmux issue is the exact issue we're running into. I'll see if the solutions there work
https://github.com/tmux/tmux/issues/597
Edit 2: I've submitted a GitHub issue with tmux. No real results yet, but it does offer some guidance on things to check on.
The problem seems to be fixed after commenting out this line from my tmux.conf:
set -g default-command "reattach-to-user-namespace -l zsh"
I also had to manually run tmux kill-server instead of relying on just re-sourcing my conf file.
When I find some time, I'll look more into what went wrong here...
Recently I've changed my default system voice via "System Preferences > Dictation & Speech > Text to Speech > System Voice". If I open a new Terminal window and use the say command, the correct voice is used. However, the previous voice is still used if I use the say command within a tmux session.
I've tried restarting, shutting down tmux completely, and opening an entirely new tmux session with tmux new-session -s foobar and still it doesn't pick up the new preferred voice.
This is really a minor issue, but it eats at me that I have no idea why it's happening. Any ideas?
I'm pretty sure this is the same root cause as that other issue: many tools that need to interact with the UI (graphics, sounds...) fail within a tmux session: say, pbcopy/pbpaste, nohup, launchctl export|getenv|setenv, subl (Sublime Text command line tool), Retina rendering of apps launched under tmux, tools trying to access KeyChain (curl, ssh...), etc.
I remember GNU screen used to have the same problem but Apple patched it and now it works fine, but tmux still has the problem.
Solution (2017-05)
Borrowing from answers in linked issue, for tmux you can do this if you have Homebrew:
brew install reattach-to-user-namespace
Then put the following in your ~/.tmux.conf:
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
I reproduced your issue on macOS 10.11.4, and the above fixed it.
See here for more info on the nature of the problem, and its workaround (using undocumented macOS APIs)
Better solution soon?
As mentioned in comment, future versions of tmux might do this dance natively, at least it's being worked on, and current master has the fix.
I'm using tmux on a macOsX moutain lion (10.8)
Whenever i'm in a terminal, pressing the Escape button results in the connection to the server being lost and tmux actually exiting. I experience the same behavior regardless in iterm2, terminal and while using any of zsh, bash or a normal login shell.
That's how it looks like:
Any hints? :)
I finally figured out that it was related to iterm2-tmux integration.
As you can read here in the Usage section just below the code box, the tmux-iterm2 integration makes the ESC key actually kill tmux, unless you actually use tmux -C.
This effect was actually undersirable for me since I was not using tmux -C and the ESC key is extremely important in programs like vim or mc.
I'm running iterm2 and when I'm in tmux mode the colorscheme I have set in vim does not show up. Only the color scheme I've set in iterm. If I run vim from shell the colorscheme appears correct - its only when I'm in tmux mode.
I've tried setting :colorscheme molokai when in vim (see screenshot below) and it doesn't change - again, the default colorscheme for iterm2 remains.
Am I missing some setting to iterm or tmux.conf? My dotfles are up on github here.
I had the same problem. Only difference was I am using solarize rather then molokai.
To fix the issue, I have set up an alias in ~/.bashrc:
alias tmux="TERM=screen-256color-bce tmux"
And set up the default-terminal option in ~/.tmux.conf:
set -g default-terminal "xterm"
Lastly, do $ source ~/.bashrc to load new alias.
I tried all the solutions above and what finally worked for me is putting the following lines in .tmux.conf:
set -g default-terminal "xterm-256color"
As #romainl mentions above, I needed to force tmux to use 256 colors by adding the -2 flag:
$ tmux -2
I added alias tmux='tmux -2' to my bash_profile, so, I don't forget :)
I just discovered why I was having a lot of confusion. I, like others here, was having a difficult time getting the default-terminal setting to take effect. I remembered that I had a tmux session in the background. I re-attached my session, closed out my processes, and closed ALL tmux processes. The next time I restarted tmux the default-terminal setting in .tmux.conf began to take effect. I don't know if others are doing this as well but I recommend closing all tmux processes before modifying the .tmux.conf file.
I got my setup to work on my local machine (OSX 10.9.5 with iTerm2) without any modification to .bashrc or .bash_profile. All I did was add the line set -g default-terminal "xterm-256color" to ~/.tmux.conf and restarted all tmux processes.
I got my remote setup (ssh to Ubuntu 14.04) to work exactly the same way without any modifications to .bashrc. I simply added set -g default-terminal "xterm-256color" to ~/.tmux.conf on my remote machine and restarted all remote tmux processes.
You can test what Vim is seeing by doing echo $TERM from within a tmux session. It kept saying screen as the value until I restarted all tmux processes, at which point it reflected xterm-256color as expected.
Hope that helps.
So this a bit on the stale side, but it's might be worth mentioning that using screen will often break the Home and End keys. Using
export TERM="xterm-256color"
it should keep the functionality of these and allow the color scheme (or powerline) to work fine.
I needed vim to display correctly with tmux in terminal on ubuntu and cygwin/mintty on windows. I got it to work by combining the answers like this.
In .bashrc:
alias tmux="tmux -2"
In .vimrc:
" use 256 colors in terminal
if !has("gui_running")
set t_Co=256
set term=screen-256color
endif
" fix cursor display in cygwin
if has("win32unix")
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
endif
based on answers from this question, this Vim wiki page and this block cursor question
In case anyone needs 24-bit color support:
Tmux supports 24-bit color as of version 2.2. If your terminal supports 24-bit color, add your terminal to the terminal-overrides setting. For example,
set -ga terminal-overrides ",xterm-256color:Tc"
My environment checklist:
macOS Sierra 10.12.3
iTerm2 3.0.14 (Report Terminal Type is xterm-256color)
neovim 0.1.7 (Enable 24-bit color by adding: xterm-256color to .vimrc)
tmux 2.3 (Add set -ga terminal-overrides ",xterm-256color:Tc" to .tmux.conf)
Nothing else I need to add in .bashrc or .zshrc.
Hope this could help.
Since this is the first result on Google and since none of the above helped..wanted to post this so that someone might find it helpful
in .vimrc:
set background=dark
set t_Co=256
HTH
I have tried all of the instructions above, and I found out the most important thing is I have to explicitly add the following line in my .bashrc file.
export TERM=screen-256color
I don't know why alias tmux="TERM=screen-256color-bce tmux" doesn't work out.
I use Sierra 10.12.1.
Just had to deal with this problem, and although all previously posted answers were helpful, they did not solve the issue in my case.
My problem was fixed by removing the following line in my .vimrc:
set termguicolors
which was redondant with another instruction anyway.
Now, with the following line found in previous anwsers in my .tmux.conf:
export TERM="screen-256color"
all is nice and colorful.
Adding the following line in .tmux.conf worked for me with macOS Sierra 10.12.6,
set -g default-terminal "screen-256color"
I'm using gnome terminal and this solved the problem, but (0) don't forget to:
killall tmux
(1) Edit .tmux.conf
# 24 bit color
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"
(2) Edit: .vimrc
" Enable true color
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
Solution posted by rinetd on tmux repo issue:
https://github.com/tmux/tmux/issues/1246
If you find yourself in the same sitation as me, that none of the above worked.. try this:
in .tmux.conf:
set -g default-terminal "xterm"
in bash config (maybe .bashrc or .bash_profile):
alias tmux="tmux -2"
and then run:
killall tmux
and then relaunch tmux
If you use tmuxinator or mux, you will need to add these in .bashrc or .zshrc:
alias tmux='TERM=screen-256color tmux -2'
alias tmuxinator='TERM=screen-256color tmuxinator'
alias mux='TERM=screen-256color mux'
These forces to use 256-color in terminal.
Then tmux, tmuxinator and mux command will all work.
I've removed the line set termguicolors, but it doesn't work.
Setting set notermguicolors instead in the .vimrc works.
In order to set up correct color and to get rid of rendering issue in both Ubuntu and Mac:
check this
From the tmux man page, adding flag as following:
tmux -2
This -2 flag forces tmux to run on 256-color mode.
This works for me
Using these two lines in my .tmux.conf worked for me, I'm using Ubuntu 20.04 with Alacritty.
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",alacritty:RGB"
Found them in an issue on alacitty's repo, in the comment provided by YodaEmbedding:
https://github.com/alacritty/alacritty/issues/109
I didn't have much luck trying to export a different TERM or set default-terminal in my .tmux.conf.
My solution for fixing vim colors within tmux was adding this line to .tmux.conf:
set -g terminal-overrides 'xterm:colors=88'
I'm not sure why this override was needed given that my TERM=xterm and I have iTerm set to xterm as well, but it seems to work.
I am using Ubuntu bionic 18.04.4 LTS and tmux 2.6.
I have the same issue and it can be resolved by simply adding this into .bashrc
export TERM=screen-256color
And ofcourse don't forget to source it.
source ~/.bashrc
Or just restart your teminal
ENV:
Fedora 29 workstation x86_64, GNOME Terminal 3.30.1
VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar 8 2019 09:25:44)
GNU bash, version 4.4.23(1)-release (x86_64-redhat-linux-gnu)
tmux 2.7
vim is using solarized scheme.
.vimrc
...
let g:solarized_termcolors=256
let g:solarized_termtrans=1
syntax enable
set background=dark
colorscheme solarized
...
The value of $TERM in bash is:
[u#loc ~]$ echo $TERM
xterm-256color
[u#loc ~]$ tput colors
256
Mehthod 1: works.
Check $TERM value inside tmux session. Get
[u#loc ~]$ echo $TERM
screen
[u#loc ~]$ tput colors
8
So, just set export TERM=screen-256color inside tmux session. This method only works in the current pane of the session.
Method 2: works.
Create ~/.tmux.conf file and add set -g default-terminal "tmux-256color" to the file.
or Just run echo "set -g default-terminal \"tmux-256color\"" > ~/.tmux.conf
Then kill all tmux sessions.
Start a new session and check the $TERM value inside tmux session. Get
[u#loc ~]$ echo $TERM
tmux-256color
[u#loc ~]$ tput colors
256
And vim colorized scheme works fine for all pane and all tmux sessions.
I also tried xterm-256color and screen-256color in ~/.tmux.conf. They all work fine for colorizing the vim scheme.
By the way, I don't have any configurations being related to this setting in my ~/.bash_profile, ~/.bashrc and ~/.vimrc.
See also https://github.com/tmux/tmux/wiki/FAQ#how-do-i-use-a-256-colour-terminal, https://github.com/tmux/tmux/wiki/FAQ#why-do-you-use-the-screen-terminal-description-inside-tmux
Other useful talks are Vim color scheme changes in tmux #699, 256-color-support-for-vim-background-in-tmux, getting-256-colors-to-work-in-tmux, tmux-term-and-256-colours-support
Assuming that you already have vim colors matching with your terminal:
Kill all tmux sessions running tmux kill-server
Create a user configuration file for tmux in ~/.tmux.conf
Add to the .tmux.conf the following lines:
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",xterm-termite:Tc"
Run in your command line echo $TERM
Replace xterm-termite with the output returned by echo $TERM
I use fedora 34.
I add this to .tmux.conf file
set -g default-terminal "xterm-256color"
Then add this to .vimrc
set background=dark
set t_Co=256
Say I'm running tmux and use "ls" to get something on the screen. Then I enter Vim to edit some file. After exiting Vim, tmux erases whatever text is above the bash prompt (not like the clear command since the prompt stays in the same place).
Is there a way to prevent this behavior? I'm using tmux 1.3 in Terminal.app on OS X.
If your version of tmux has this option, add this line to your ~/.tmux.conf:
set-window-option -g alternate-screen on
Try putting this in your .vimrc file:
set t_ti= t_te=