
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.
The underlying feature is called alternate screen
and basically its a feature of your terminal (be it xterm, gnome-term or even your console).
If you want to get rid of it, you have a few options:
A prime example is the less option .-X
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 ~/.Xdefaults:
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 ti and te in termcap and smcup / rmcup in terminfo. (Yay! for gratuitous differences). What we will be doing, is to override these by placing a suitably modified file in your $HOME.
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 :ti@:te@xterm and xterm-color.
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@
to your ~/.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…
– Sec
A quick fix for me was:
TERM=vt100
vi/vim, less, and hopefully others, respect that. Since vt100 doesn't support the alternate screen it isn't used. This also nicely disables vim color syntax highlighting.
I was searching how to do in tmux, what I did with screen (terminfo :@ti:@te). turns out, i could just disable alt screens in PuTTY to fix everything! derp
knarf wrote on Thu, 21 Oct 2010 11:17
In screen geht auch: altscreen off