5

Neither less or less -X clear screen on exit. At the same time, vim does....

Env iTerm2, protocol mosh, server Centos + tmux + zsh

iTerm2: report term as xterm-256color

tmux: set -g terminal-overrides 'xterm*:smcup@:rmcup@', no change to alternate-screen

$TERM is final set to screen-256color

I also tried tput smcup | od -c and tput rmcup | od -c

suggested here. It outputs correct answer.

Anthon
  • 79,293
Jiesi Luo
  • 101
  • 2
    You disabled smcup and rmcup in tmux, and now they're not working? That seems to be expected. – Mikel Sep 19 '14 at 02:46
  • @Mikel I tried deleting set -g terminal-overrides 'xterm*:smcup@:rmcup@' in my .tmux.conf. less -X still doesn't clear screen. – Jiesi Luo Sep 19 '14 at 15:52
  • It's also interesting that you say it works in Vim. Hmm... – Mikel Sep 19 '14 at 15:53
  • Wait, less -X isn't supposed to clear the screen. What happens without the -X option? – Mikel Sep 19 '14 at 15:54
  • What? Shouldn't less -X clear the screen while less not? Anyway, I tested less, it still didn't work. So basically less and less -X both don't clear screen in any case I tested. – Jiesi Luo Sep 19 '14 at 15:56
  • 2
    No, it's the other way around. less sends smcup on startup, and rmcup on exit, so after you quit less, you are taken back to your shell and can see your shell output but not what you were viewing in less. The -X flag disables sending those terminal escapes, so the less output is mixed in with your shell output. – Mikel Sep 19 '14 at 16:02
  • @Mikel thanks. Any idea why less still doesn't work here? – Jiesi Luo Sep 19 '14 at 16:18
  • 1
    What is the output of type less, echo $LESS end echo $LESSOPEN? – jimmij Sep 19 '14 at 16:33
  • Does less -+X somefile clear the screen? – Gilles 'SO- stop being evil' Sep 19 '14 at 21:24
  • @Gilles No, it doesn't.

    @jimmij type less: less is an alias for less -R less is /usr/bin/less; $LESS is -F -g -i -M -R -S -w -X -z-4. $LESSOPEN is | /usr/bin/env lesspipe.sh %s 2>&-

    – Jiesi Luo Sep 19 '14 at 23:50
  • I got it! After I clear $LESS less somefile will clear screen on exit. I don't know why less -+X doesn't work when $LESS is set though.. It should looking from man page.. Maybe a bug for less – Jiesi Luo Sep 19 '14 at 23:58
  • 1
    $LESS is variable with default options for less. You had -X there as I suspected, so basically you started less -X all the time. – jimmij Sep 20 '14 at 10:58
  • @jimmij thanks! I thought default means with no arguments. – Jiesi Luo Sep 23 '14 at 05:02
  • do you want to clear screen? i think clearing screen is mostly useless. maybe really you want to restore screen as was before running less + history line for the less run? – qdinar Jun 22 '21 at 14:16

2 Answers2

4

The issue is my $LESS contains -X. Plus -+X will set less to it's default behavior, which is whatever is specified in $LESS, NOT no -X. Thus I was running less with -X all the time. That's why neither cleaned the screen.

Jiesi Luo
  • 101
1

I've had the same issue. And this thing happened only in iTerm2 on my mac. So i found the solution. You've just to switch off 'Save lines to scrollback in alternate screen mode' checkbox.

This option is stored in each profile in 'terminal' tab. The screenshot is follow. Screenshot