Bash Display – How to Prevent Vim Text Display After Exit in GNU Screen

bashdisplayterminalvim

Currently when I am not using screen utility, I am able to see the VIM content wiped out of the display when I quit VIM.
However when I am using GNU Screen utility and opening a file in one of the screen window and closing it, I can see the trailing file content on the display. It’s not wiping out the file content from the display the way it does when I am not using GNU Screen.

I found the below post where it has been discussed without GNU Screen.

How to set the bash display to not show the vim text after exit?

In my case, in both the scenario [with and without GNU Screen] the Terminal Type is “xterm”. But the behavior is different when I close a VIM file.

Kindly help.

Best Answer

GNU screen supports the xterm alternate-screen feature using the altscreen setting in your .screenrc file. According to the manual:

— Command: altscreen state
(none)
If set to on, "alternate screen" support is enabled in virtual terminals, just like in xterm. Initial setting is ‘off’.

A quick check shows that screen is actually simulating the feature, because it clears and/or restores the screen contents itself without sending the control sequence used by xterm. The screen feature works whether or not the actual terminal (or its terminal description) supports the alternate screen feature. You can test this by setting TERM to "vt100" before running screen.

You can read more about the alternate screen feature in the xterm FAQ Why doesn't the screen clear when running vi?

Related Question