2

The default behavior for 'less' is to clear the screen after quitting. This behavior stopped when I started using:

export TERM=xterm

Now 'less' leaves the last page I viewed on the screen, and I want to re-enable the default behavior of clearing the screen.

Googling this problem I found that people use the following command in their ~/.screenrc:

altscreen on

I'm not sure if this is a mac-issue but I don't have this command available.

I'm using bash shell on Mac terminal and I have no $LESS environment variable defined.

Hennes
  • 65,804
  • 7
  • 115
  • 169
Dana
  • 121

3 Answers3

2

Some clarification is needed: less will only clear the screen as a part of displaying a new page. What is described in the question is the alternate screen, an xterm feature that Terminal.app supports.

When you see the screen cleared, that is because the terminal has switched to the alternate screen temporarily (to run less) and has switched back to the normal screen (showing just your shell prompt and whatever preceded that before running less).

less gets the information on how to switch to/from the alternate screen from the terminal description, using $TERM to find this information. I don't see this in OSX now (the question dates from 2011), but some developers dislike the feature and remove it from the terminal description (for example, FreeBSD).

The question did not say what $TERM was before changing it to xterm. That used a different terminal description, where the feature had not been removed.

2

Take a look at your $LESS environment variable and make sure it doesn't specify -X. I specifically add this to $LESS, because I don't want the screen cleared. Here is a snipet from the manpage:

-X or --no-init Disables sending the termcap initialization and deinitialization strings to the terminal. This is sometimes desirable if the deini- tialization string does something unnecessary, like clearing the screen.

KeithB
  • 10,386
0

This answer is an extension to the answer by @KeithB.

check the options of LESS by echo $LESS. If it has option -X, remove it.

LESS="options"; export LESS

In options include options other than -X. More information, check the manpage.