Which is the correct way to config the $TERM and tmux?

5,237

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>
Share:
5,237

Related videos on Youtube

m0squito
Author by

m0squito

Updated on September 18, 2022

Comments

  • m0squito
    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
    m0squito over 11 years
    The 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
    romainl over 11 years
    It'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 as xterm-256color and add this set-window-option -g xterm-keys on to your .tmux.conf?
  • m0squito
    m0squito over 11 years
    vim 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
    romainl over 11 years
    I 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
    romainl over 11 years
    This is the piece of code in question. Don't know if it is of any use to you.
  • m0squito
    m0squito over 11 years
    Well it sets the $TERM to xterm-256color and it looks cool :)
  • slhck
    slhck about 11 years
    We 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
    nebulous about 5 years
    this solved my insert-mode arrow key issues with TERM=tmux-256color. 👍