vim in tmux background color changes when paging

moshen picture moshen · Jun 21, 2011 · Viewed 10k times · Source

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!

Answer

sunaku picture sunaku · Feb 26, 2013

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