Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

migrated from stackoverflow.com Oct 5 '10 at 12:31

This question came from our site for professional and enthusiast programmers.

superuser.com/questions/871170 is related. –  JdeBP Jan 30 at 17:32

4 Answers 4

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.

share|improve this answer

This has to do with your terminal and your machine's settings dealing with the terminal info. One portable solution is to use GNU Screen. Open one window for Vim and another for Bash, thereby separating the two sessions. If you are using a graphical terminal such as xterm on X11, Gnome Terminal on Gnome or Terminal.app on OS X then you can open a new window or tab to gain the same effect.

share|improve this answer

Tim. Both of the above answers are correct. Vim switches the terminal to an "alternate screen" if the capability to do that is defined in the termcap entry for $TERM.

You say "in some terminals (...it works right...)" and "in others (...it works wrong...)"

Are you running the exact same terminal emulator for all of those terminals?

For example, on my home linux box, I have gnome-terminal, xterm, Konsole, yakuake, and probably a few more I've forgotten about, along with the "virtual terminals" associated with the ctrl-alt-F1...ctrl-alt-F6 or so. Most of these can work with the "standard" termcap entry for "xterm" - except the virtual terminals which have a terminal definition named "linux".

Check the terminal emulator itself and the value of $TERM on terminals that work and on ones that don't, to see what's different. Also, if you're logged in as a different user sometimes, that could be at the heart of the issue - since each user has his own .bashrc various settings can differ from user to user.

Hope that helps!

share|improve this answer

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
share|improve this answer
wouldn't that be export $TERM? –  chrsblck Feb 22 '14 at 23:03
@chrsblck: No, because export exports the name (eg TERM in this case) as an environment variable rather than a local variable. If you used export $TERM in this example then the $TERM var would resolve to xterm you would set the env var $xterm, which is probably not defined. Good question though, it always looks wrong to me too. –  ekerner Feb 23 '14 at 14:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.