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:

  1. Edit ~/.bashrc, export TERM=xterm-256color. Re-apply .bashrc if necessary.
  2. echo $TERM to verify.
  3. 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.
  4. Edit infocmp.txt, remove rmcup and smcup capabilities.
  5. Recompile capabilities (to a local directory first): tic -o . infocmp.txt.
  6. sudo cp x/xterm-256color /lib/terminfo/x/
  7. Restart shell?