Exorcising the Evil Alternate Screen describes how to create a different xterm-derived terminal type that disables the alt screen functionality. I often prefer to edit the xterm terminal type directly so that the problem is solved once and for all across the entire machine, typically when working in VMs.
I always have to look up again how to do that (as opposed to creating a new term type), so I've written it down here:
- Edit ~/.bashrc, export TERM=xterm-256color. Re-apply .bashrc if necessary.
- echo $TERM to verify.
- infocmp >infocmp.txt. Should say something like "Reconstructed via infocmp from file: /lib/terminfo/x/xterm-256color" at the top. Remember this path for later.
- Edit infocmp.txt, remove rmcup and smcup capabilities.
- Recompile capabilities (to a local directory first): tic -o . infocmp.txt.
- sudo cp x/xterm-256color /lib/terminfo/x/
- Restart shell?