39

I am using vim in 256 color mode on Solaris (connected via Putty on Windows). Everything looks great and works fine outside of tmux, but within tmux the background color changes periodically when paging/scrolling through a file.

Here is how it's supposed to look:

Here is how it appears after paging around a bit:

Thanks!

moshen
  • 1,114
  • 2
  • 11
  • 18

4 Answers4

54

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.

Per the above link, BCE can be set in .vimrc by adding the following

if &term =~ '256color'
    " disable Background Color Erase (BCE) so that color schemes
    " render properly when inside 256-color tmux and GNU screen.
    " see also http://snk.tuxfamily.org/log/vim-256color-bce.html
    set t_ut=
endif
Daniel
  • 3,243
  • 2
  • 32
  • 31
sunaku
  • 2,156
  • 19
  • 10
  • Is there any reason to _not_ do this all the time? Does it slow down rendering or something like that? – dtauxe Jul 22 '20 at 19:32
17

Adding an alternative solution, as I ran into this problem myself and only just solved it. I had the correct TERM value, the terminfo file was there, etc., but the background would still only be drawn behind cells that contained printable characters, or cells to the left of them.

If you switch between GUI vim and CLI vim often, you may have put something like this in your .vimrc file at some point:

if !has("gui_running")
    set term=xterm
endif

(Or really any overriding at all of the TERM variable within .vimrc)

Change the terminal override to screen-256color.

...
set term=screen-256color
...
Andrew
  • 12,821
  • 2
  • 26
  • 18
  • 2
    This worked for me as well. Except that it seems to break a lot of keyboard mappings (e.g. arrows in CommandT, ctrl+arrow mappings) :/ – Henrik N Mar 04 '12 at 21:02
  • 2
    `set term=screen-256color` in `.vimrc` helped me. Thanks! – Zelid Apr 19 '13 at 20:15
8

This looks like an issue with your term setting, or terminfo.

Make sure that your term in tmux is TERM=screen-256color and that your solaris box has the correct terminfo.

jasonwryan
  • 4,416
  • 1
  • 28
  • 25
  • That seems to do it, but when I switch to screen-256color my F keys stop working. – moshen Jun 21 '11 at 20:23
  • F keys as in standard {F,f} or as in function keys? – jasonwryan Jun 21 '11 at 20:42
  • 1
    Function keys... I figured it out though, it was a PuTTy thing ( http://www.howtogeek.com/58487/how-to-easily-multitask-in-a-linux-terminal-with-byobu/?amp ), Thanks! – moshen Jun 21 '11 at 20:50
0

This bug is fixed in vim 7.4 patch 7.4.1942

Relevant issue: 804

ninrod
  • 523
  • 6
  • 25