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.

  • 2
    You disabled smcup and rmcup in tmux, and now they're not working? That seems to be expected. – Mikel Sep 19 '14 at 2: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
  • 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
  • 1
    What is the output of type less, echo $LESS end echo $LESSOPEN? – jimmij Sep 19 '14 at 16:33
  • 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

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.

| improve this answer | |

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

| improve this answer | |

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.