Which is the correct way to config the $TERM and tmux?
Solution 1
As explained here, disable Background Color Erase (BCE) by clearing the t_ut
terminal option (run :set t_ut=
in Vim and then press Control+L to refresh the terminal's display) so that color schemes work properly when Vim is used inside tmux and GNU screen.
This way, you can keep your TERM
value as xterm-256color
for proper key detection while also getting proper Vim color scheme rendering too! :-)
Solution 2
Because you didn't state exactly what problems you had with keys here is a shot in the dark.
These lines in my ~/.vimrc
make the arrow keys work properly in Vim in tmux:
nnoremap <Esc>A <up>
nnoremap <Esc>B <down>
nnoremap <Esc>C <right>
nnoremap <Esc>D <left>
inoremap <Esc>A <up>
inoremap <Esc>B <down>
inoremap <Esc>C <right>
inoremap <Esc>D <left>
Related videos on Youtube
m0squito
Updated on September 18, 2022Comments
-
m0squito over 1 year
I am using gnome-terminal with bash.
When I set xterm-256color for $TERM and in .tmux.conf most of the things work but when I try to change the colorscheme of vim the things mess up.
When I set screen-256color for $TERM and in .tmux.conf the colors work ok but most of the keys go mad. I've tried some of the suggestions from the last link but when I ssh the arrows crash even on the command line..
So how to configure tmux?
-
m0squito over 11 yearsThe problem is just like the one described in the link - when I use CTRL + arrow, it deletes some lines. And this mappings did not help.. Also I am not very sure that I should use screen-256color (although I read somewhere that tmux should be used with it). The idea is that if I use xterm-256color, then when I ssh I don't have to do any config.
-
romainl over 11 yearsIt's described in an external link, not in your question. You shouldn't expect anybody to go play pokemon with the pieces of information necessary to understand your problem. Anyway, What is the output of
:echo &term
in vim without anything$TERM
-related in your config files? Could you try setting your$TERM
asxterm-256color
and add thisset-window-option -g xterm-keys on
to your.tmux.conf
? -
m0squito over 11 yearsvim without tmux - xterm; vim with tmux - xterm-256color; Setting the $TERM to xterm-256color and adding the command that you said got me to the problem with the colorschemes.
-
romainl over 11 yearsI totally forgot that my
.bashrc
at home has got a fairly involved piece of code to deal with wrong colors. I'll dig it up when I'm back home. IIRC, it's a 20+ lines conditional block that is meant to set$TERM
and a few other settings correctly. -
romainl over 11 yearsThis is the piece of code in question. Don't know if it is of any use to you.
-
m0squito over 11 yearsWell it sets the $TERM to xterm-256color and it looks cool :)
-
slhck about 11 yearsWe noticed you recently posted the same answers to multiple questions. If the questions happen to be about the same issue, please flag them for our attention to have them closed as duplicates. In general, please don't post the (verbatim) same content as an answer to multiple questions. Thanks.
-
nebulous about 5 yearsthis solved my insert-mode arrow key issues with TERM=tmux-256color. 👍