How to replace vim screen buffer with previous bash activity after quitting?

I'm trying to find out what a bash (or vim) feature is. Here's the scenario. I'm in a bash terminal, then edit something with vim, then exit back to bash. In some terminals, the vim session screen disappears to show the previous bash shell activity ( this is what I want? ).

In others, the vim session screen buffer remains (hiding old bash shell activity). I'll have to either clear the screen, or wait until my bash activity pushes that vim session buffer out of the screen.

How can I control this behaviour to replace vim session buffer with previous bash activity?

Thanks Tim


Vim sends t_ti and t_ks to the terminal when a session is started and t_te and t_ke when it ends. The t_ti and t_te sequences cause the terminal to switch to its alternate screen.

In your ~/.vimrc file you can make vim leave the document on screen when it exits by including this line:

set t_ti=""

if you have a line similar to that, removing it should make the previous terminal contents appear when you exit vim.


A cause for this problem can be using the program screen. I find that when I'm in a screen session vim can not return the terminal state.

Not sure if its specific to screen or to the screen/vim combo in Ubuntu 15.10. Same cause as described above, I guess screen has different termcap.


Simply add a line to your ~/.bash_profile file to export TERM as xterm each time you login. Do as follows;

echo "TERM=xterm; export TERM" >> ~/.bash_profile

Now next time you login your problem will be fixed, and if you dont wanna re-login you can do one of ...

// either ...
export TERM=xterm
// ... or ...
TERM=xterm; export TERM
// ... or ...
source ~/.bash_profile