0

I have a question just opposite to Is there any way to exit "less" without clearing the screen?: my less exits without clearing the screen, but I have never used -X.

The options I use is as follows:

$ echo $LESS 
-N -g -i -M -R -w -z-4
$ echo $LESSOPEN
$
$ echo $TERM
ansi

I remember when my less started to change its behavior: when I was trying to type something to another application but my cursor was in the terminal with less opening. When I realized I'm typing into a wrong place and tried to quit less, the file contents start to remaining to my terminal. I'm using MacOS terminal (not iTerm2).

As @roaima suggested, my issue is to get the less's standard behavior without -X. However, -+X does not work; and -X is not in LESS.

I'm using OSX Terminal.app, not iTerm2.

1

If you really want less to clear the screen when it exits you can redefine the command like this

less() { command less "$@"; clear; }

On the other hand, if you want less to save the original content of the screen and restore that when it exits, this should be standard behaviour. (It's managed through the ti and te entries of TERMINFO and/or TERMCAP. These are set according to the terminal type as evidenced with echo $TERM.)

You can try forcing off the -X option with

less -+X

But if that doesn't work either, provide the result of running an echo $TERM command, and it should be possible to determine what the ti and te values are, and therefore why they're not saving and restoring the screen.

  • Thank you @roaima, My issue is to get standard behavior, but less -+X does not work. $ echo $TERM returns ansi – paracosmo Aug 20 '18 at 2:08
  • Have you read the answer I've highlighted in the duplicate? – roaima Aug 20 '18 at 6:32
  • Yes, but I'm not using iTerm2. I'm having this issue in the OSX Terminal.app and I can't find anything similar to "Save lines to scrollback in alternate screen mode" in its preference... Or did I missed something? – paracosmo Aug 21 '18 at 7:34
  • 1
    Yes! You're not updating your question with this information you gradually disclose. People can't know what you don't tell them. – roaima Aug 21 '18 at 7:56

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