Many of you probably know the annoying behaviour of console-based programs like less or vi restoring the screen after exiting so that the text you just had there vanishes.
I never understood why you'd want that, and its commonly enabled by default on Linux machines.
If you want to get rid of it, you have a few options:
A prime example is the less option
This is useful as a quick ad-hoc solution, but not really feasible for everyday use - You don't really want to (re-)configure every program.
XTerm has an option located in the Ctrl+Middle mousebutton -Menu and is called
Enable Alternate Screen Switching. Turn if off and all programs within will behave nicely.
If you want it for all your xterm windows, you can add something like this to your
XTerm*titeInhibit: true UXTerm*titeInhibit: true
If you're using gnome-terminal, this is not for you. Gnome-terminal simply provides no way to disable this feature. Boo
All (well-behaved) programs check if your terminal supports alternate screens before using them. This information is stored in the system terminfo or termcap database. Whether your system is using termcap or terminfo is an historical thing – Linux/SysV based systems tend to use terminfo, BSDish systems termcap.
This database has an entry for every terminal type your system supports. Your terminal is stored in the
$TERM environment variable. Go and check your
$TERM value. It is most probably
xterm or something similar.
The capabilities for alternate screen are called
te in termcap and
rmcup in terminfo. (Yay! for gratuitous differences). What we will be doing, is to override these by placing a suitably modified file in your
For terminfo it works like this:
infocmp -l $TERM > $TERM.src vi $TERM.src # remove the smcup= and rmcup= parts till the next , mkdir ~/.terminfo tic $TERM.src
This dumps the current entry to a file, and
compiles it into a file in
~/.terminfo/ after you modified it.
Termcap just uses plaintext files, so go look into your system termcap file (
/usr/share/misc/termcap or similar), and find the entry for your current
$TERM. On my system it looks something like this:
xterm|xterm-color|X11 terminal emulator:\ :ti@:te@:tc=xterm-xfree86:
copy that into
~/.termcap, and add
at the beginning of the second line to disable these two capabilities. As you can see from my example on FreeBSD this is done by default for
That should fix it for you.
Lastly, if you are using screen, there is a simpler way to do it. Screen has a built-in feature to edit the termcap/terminfo for programs running inside. Simply add
termcapinfo xterm* ti@:te@
~/.screenrc (of course replace
xterm with your
$TERM in use before you start screen)
I hope this lengthy explanation did not bore you too much…