ITerm2 -> ssh -> gnu screen -> split window: scroll wheel not working

gnu-screeniterm2sshterminal

I'm using Mac OS X as a workstation. With iTerm2, I connect to a remote host (Ubuntu Server) using this command:

ssh -t user@host screen -D -R -R

But I can't get the scroll wheel to work correctly, especially when using split windows. When I'm scrolling up I expect to see the scrollback buffer of the current split window; instead, the entire iTerm2 scrollback buffer goes up, revealing part of the output of the commands before the ssh.

Putting termcapinfo xterm* ti@:te@ on ~/.screenrc, as suggested here, both in local and remote home directories, does not change the behavior.

The TERM environment variable is xterm-256color in both consoles.

Best Answer

The related posting Mac OS X terminal and GNU screen scrollback essentially advises you to suppress switching to the alternate screen of xterm. While in the alternate screen, you would not necessarily be able to use the scroll-wheel to see xterm's scrollback. A program running in xterm would only see the escape sequences if it enables the xterm mouse protocol.

By default, screen does not do this. It does have a setting which enables the mouse protocol, called mousetrack:

This command determines whether screen will watch for mouse clicks. When this command is enabled, regions that have been split in various ways can be selected by pointing to them with a mouse and left- clicking them. Without specifying on or off, the current state is displayed. The default state is determined by the "defmousetrack" command.

But

Instead (see the first couple of links), some users have altered the xterm configuration to send screen-commands as the result of the scrolling wheel. A drawback to doing that is that it works only for the combination of xterm+screen.

Related Question