Scrolling up in iTerm2 shows previous Vim sessions

4

2

In iTerm2 (Version 2.1.4), when I scroll up to see previous commands, I'm seeing chunks of previous Vim sessions, which I don't want to see. Any idea why that would be happening and how to fix that?

As an example, here's some output after I typed a line of a file in Vim, then scrolled up. The top line is a remnant of the Vim session. (I have line numbers on in Vim, which is where the 1 comes from.)

  1 I'm typing a line in Vim.
Last login: Tue Jan  5 10:16:18 on ttys001
imac:~$ vi test.txt
imac:~$ cat test.txt
I'm typing a line in Vim.
imac:~$

Sometimes much larger remnants are displayed. Any thoughts would be appreciated.

Ben Lindsay

Posted 2016-01-05T15:20:52.770

Reputation: 181

Possible duplicate of How can I partially clear my terminal scrollback?

– Thomas Dickey – 2016-01-06T00:31:04.497

I don't think this has anything to do with clearing scrollback. I want my scrollback history available, but I don't want it interspersed with lines from Vim sessions when I scroll up. In the small example I placed above, the line starting with Last login: should be the top of the session. Nothing should show up above it if I try to scroll up, but what's showing up there is a remnant from a Vim session that shouldn't show up there, and doesn't show up if I'm in Terminal.app instead of iTerm2. – Ben Lindsay – 2016-01-06T15:42:38.623

@BenLindsay, any resolution to this? I see the same happening in my terminal on Mac. – Jens – 2018-04-19T07:10:25.650

@Jens Yes, George Nachman resolved my problem a long time ago. I posted an answer. Hope that helps! If you're seeing that on Terminal.app then I can't help you, but this should fix it on iTerm2! – Ben Lindsay – 2018-04-19T18:24:14.600

Answers

3

George Nachman, the iTerm2 guy, ended up solving my problem here. In short, I just needed to uncheck Prefs > Profiles > Terminal > Save lines to scrollback in alternate screen mode in the iTerm2 menu.

Ben Lindsay

Posted 2016-01-05T15:20:52.770

Reputation: 181

Thank you. I’m using rxvt on XQuartz and was hoping for a hint I’ll dig around, but it looks like the terminal itself is the culprit which needs massaging?

– Jens – 2018-04-19T21:53:31.227

0

I’m running urxvt in XQuartz and had the same problem. What fixed it for me was to add the following to ~/.Xdefaults:

urxvt*secondaryScreen: 1
urxvt*secondaryScroll: 0

From the man pages:

secondaryScreen: boolean
Turn on/off secondary screen (default enabled).
secondaryScroll: boolean
Turn on/off secondary screen scroll (default enabled). If this option is enabled, scrolls on the secondary screen will change the scrollback buffer and, when secondaryScreen is off, switching to/from the secondary screen will instead scroll the screen up.

Jens

Posted 2016-01-05T15:20:52.770

Reputation: 103