Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I connect to Z-Shell on a Red Hat Enterprise Linux 6.2 machine via Putty. After I exit a full-screen process, eg Vim and less, in Unix shell, the shell prompt starts at the last line of the screen. The screen above still shows the context of that process, so I lost all stuff that shell showed before I opened that process.

This doesn't happen in my own Ubuntu box, where after exiting a process, I get back to the line below the last command I typed.

What options can I change(maybe in zshrc?) to make it behave like my Ubuntu box?

share|improve this question
up vote 1 down vote accepted

I've seen this problem too. Check your PuTTY settings under Terminal->Features. If "Disable switching to alternate terminal screen" is checked, uncheck it. (All my settings on that page are unchecked.) The help for that option looks promising.

Failing that, this page I found by googling might give you some ideas. You might be able to set some terminfo stuff to get it working right.

share|improve this answer

After fixing this very issue long ago, I ran into a similar problem, where Vim did not have this issue, but less did. This affected all programs that use less too, like man. The cause, I found, was the LESS environment variable, which lists arguments to automatically be passed to less whenever it is invoked. The option within LESS that caused this was -X:

-X or --no-init

Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deinitialization string does something unnecessary, like clearing the screen.

I also learned from Unix & Linux – “less --quit-if-one-screen without --no-init that if you disable -X/--no-init, you must disable -F/--quit-if-one-screen too (if you have it set).

To fix less so that it always restores your screen on exit, change the value of LESS in the appropriate shell initialization file. This will be .bashrc for Bash, .zshenv for Zsh, and .config/fish/ for Fish. To this file, add the command export LESS='<all the flags you want, without -X or -F>', or set -gx LESS <flags> for fish. You can run echo $LESS beforehand to see the existing flags to copy into your export/set statement.

share|improve this answer

I figured it out! All I have to do is set $TERM to xterm. It used to be linux

export TERM=xterm 

Thanks for the link and hints, David!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .