I always thought Vim restored the previous contents of the screen upon closing. This allows me to remember what commands I was typing previously and what I wanted to do next.

Recently I've been using Debian 6 and Ubuntu (CLIs only) in a VM for a development project and I've been extremely annoyed with how Vim is operating. After I close the file its contents stay on the screen making me second guess whether I'm still in Vim or not, and having to use history to find out what I typed previously.

I've been unable to find any solution. Using tput smcup and rmcup for instance does absolutely nothing.


Edit your .screenrc file and add the command "altscreen on".

Reference from the manual:

— Command: altscreen state

    If set to on, "alternate screen" support is enabled in virtual 
    terminals, just like in xterm. Initial setting is ‘off’. 

Try enabling the alternate screen on your terminal emulator. In xterm, Ctrl+Middle Click will give you a menu, then select "Enable Alternate Menu Switching".
If that works, you can edit your .Xresources to contain: xterm*titeInhibit: false and then type $ xrdb -merge < ~/.Xresource. I haven't tested that config though.

  • No no X, no xterm. :\
    – peu ping
    Jun 23 '12 at 14:57
  • @peuping Sorry I should have realised. It seems that the virtual console doesn't support the alternate screen (I can't find an authoritative link). You could try GNU screen or tmux terminal multiplexers. For example in a screen session you could try $ screen vim which would start your vim session in a new pseudo-terminal and leave your command line untouched. Jun 23 '12 at 15:55

Under VIM help for restorescreen:

                        'restorescreen' 'rs' 'norestorescreen' 'nors'
'restorescreen' 'rs'    boolean (default on)
                        {not in Vi}  {only in Windows 95/NT console version}
        When set, the screen contents is restored when exiting Vim.  This also
        happens when executing external commands.

        For non-Windows Vim: You can set or reset the 't_ti' and 't_te'
        options in your .vimrc.  To disable restoring:
                set t_ti= t_te=
        To enable restoring (for an xterm):
                set t_ti=^[7^[[r^[[?47h t_te=^[[?47l^[8
        (Where ^[ is an <Esc>, type CTRL-V <Esc> to insert it)

You may have a

set norestorescreen


set restorescreen!

in your .vimrc somewhere. (or one of your additional scripts). The default is to restore the previous screen's contents.

Remember to look for the short versions (nors / rs!) if you don't find the whole option name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.