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.

migrated from stackoverflow.com Jun 30 '11 at 15:13

This question came from our site for professional and enthusiast programmers.

  • 1
    This isn't a duplicate. The other question explicitly asks about the problem inside GNU screen. This one has nothing to do with screen, as evidenced by, "I don't have [altscreen] available" and "I'm using bash shell on Mac terminal." – peth Jun 30 '11 at 19:02
  • What happens when you call less like: less -+F -+X <file>? If that changes the behavior, your less is configured to behave that way somewhere in you system configuration. If not, it's likely that your terminal doesn't support the alternate screen feature or doesn't have it enabled. You'd need the reverse of superuser.com/questions/136162/… or get a terminal that has the alternate screen feature. – peth Jun 30 '11 at 19:11
  • @peth: This really isn't a duplicate question. As for your question, no matter how I play with the command line options, the last page always remains on the screen. I don't think this has something to do with the less configuration since this only started happening after I defined export TERM=xterm. Thanks for your help! – Dana Jul 1 '11 at 16:02
1

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.

  • I have no $LESS environment variable defined at all – Dana Jun 30 '11 at 17:20
  • As mentioned in the question, this only started happening after I defined export TERM=xterm, so I believe this is not a problem of less definitions. – Dana Jul 3 '11 at 22:50
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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.