Using the scrollwheel in GNU screen
Asked Answered
C

10

297

How can I set up GNU screen to allow the mouse's scrollwheel to scroll around in the scrollback buffer? I tried to Google about this, but most hits were on how to allow applications inside screen to use the scrollwheel.

Cockloft answered 11/12, 2008 at 12:1 Comment(1)
Not using screen nowadays, but the upvotes seem convincing enough. :)Cockloft
M
430

I believe you can just add a line like this to your ~/.screenrc:

termcapinfo xterm* ti@:te@

Where "xterm*" is a glob match of your current TERM. To confirm it works, ^A^D to detach from your screen, then screen -d -r to reattach, then ls a few times, and try to scroll back. It works for me.


What is this magic? Well, let's consult the manual pages.

screen(1) says:

termcapinfo term terminal-tweaks [window-tweaks]
  [..]
  The first argument specifies which terminal(s) should be affected by this
  definition. You can specify multiple terminal names by separating them with
  `|'s. Use `*' to match all terminals and `vt*' to match all terminals that
  begin with "vt".
  [..]
  Some examples:

      termcap xterm*  LP:hs@

  Informs screen that all terminals that begin with `xterm' have firm
  auto-margins that allow the last position on the screen to be updated (LP),
  but they don't really have a status line (no 'hs' -  append  `@'  to turn
  entries off).  Note that we assume `LP' for all terminal names that start
  with "vt", but only if you don't specify a termcap command for that terminal.

From termcap(5):

String capabilities
    [..]
    te   End program that uses cursor motion
    ti   Begin program that uses cursor motion
Maternity answered 14/7, 2009 at 14:54 Comment(25)
I followed Pistos's suggestion, and it partially works. As he describes, I can enter some commands (to produce enough output to scroll the screen), and then use the mouse-wheel to scroll back through the preceding lines. In fact, I'm using screen via Konsole in KDE (tabbed xterm, basically), and the scrollbar for the Konsole window works the same way. But there's a problem: If you switch between screen's windows (^A-n, ^A-p), your scrollback buffer gets messed up. The contents of any windows you switch into will just get 'tucked' up into your scrollback buffer. That really diminishes it.Kone
The behaviour you describe indeed happens, even for me. It's something I live with; I just alternate between scroll wheel and Copy Mode.Maternity
But this scrolls around in the command history. I want to scroll through the output buffer.Cockloft
That's not the behaviour I experience, JesperE.Maternity
This works for me ssh'ing into ubuntu from Mac OS X using iTerm. Thanks!Mckissick
@JesperE: I experienced it scrolling the command history as well (I'm using Ubuntu's GNOME terminal). I fixed it by going to Edit -> Profile Preferences -> Scrolling, and unchecking "Use keystrokes to scroll on alternate screen". Note that I still needed to use Pistos's fix.Eurystheus
To make this work, you must switch screens away and back (e.g. ^A-a twice) every time you want to scroll back. And yes there's only one combined buffer for all your screens.Schiller
This works for me in OS X Lion with momentum scrolling. Sweet!Mastectomy
In addition to working in OS X Lion, this also works in Putty, iSSH and Prompt (by Panic). This line should be present in all .screenrc files!Mastectomy
cd && echo -e "termcapinfo xterm* ti@:te@" > .screenrc works in centosAnapest
the previous link answer fails using Emacs, although if one could modify terminfo they may get it to work ... for me, I am here precisely because I'm not a Terminfo guru. So, this answer works for me using Emacs.Infatuation
This enables scrolling in the terminal not scrolling in the screen session. I.e. if you work with split regions or switch a window you won't be able to scroll back in this region and instead you'll scroll back in the terminal output and see the output as it was before you split the region or changed the window.Sundry
yeah , completely agree with g_daniel this solution doesn't scroll in screen section , which is what I expectMariano
For mintty with cygwin I had to use terminfo xterm* ti=:te= but it worked perfectly.Bullivant
Thanks for the answer! It's perfect. Of course screen can't mess with whole particular terminal program buffer but it's neat for quick scrolls to have it working with the wheel. Otherwise use proper screen scrolling.Magnetism
It did not work for me on Ubuntu 14.04, even with the tip by @MichaelKrebsLesslie
@FelipeMicaroniLalli I confirm this here on Lubuntu 14.10, which should be pretty alike to yours. A total failure with this termcapinfo tip. Maybe Ubuntu & flavors are using some distro-specific settings again which prevent this from working properly. :( Too bad.Darg
Bear in mind that my answer is 5 years old. Who knows what has changed since then as far as screen or the idiosyncrasies of the various distros.Maternity
glob match of your current TERM would be helpful to set out what this means.Villainous
With this enabled, the terminal does not clear when detaching from screen with Ctrl-A D. Is it possible to restore the default clear functionality when detaching from a screen session?Roundtree
echo 'termcapinfo xterm* ti@:te@' >> ~/.screenrcKoski
Without screen, mouse scrolling scrolls through the terminal window unless I'm inside a program like less, which takes over and scrolls in the file I'm viewing. With this command, I can scroll through the history but less won't let me use the mouse scroll. Is there any way to get both to work?Macrography
I found screenrc file at /etc/screenrcOrgel
@Villainous run echo $TERM. The output will be something like xterm-256color. So, xterm* glob matches our current TERM (treat the * as a wildcard).Doubletalk
Thank you, thank you, thank you! Works perfect when ssh-ing into Ubuntu Xenial after creating a .screenrc with just your termcap line in it. I don't know how long screen annoys me with this ...unusual behaviour.Overbalance
R
91

In screen, you must first enter "scrollback mode" (or "copy mode") to be able to scroll around in the scrollback buffer: key combo Ctrl-a Esc, or Ctrl-a Ctrl-[. Then you can scroll around the history using Up and Down keys (or Ctrl-b, Ctrl-f to move a page).

In that mode, your mousewheel should also work, if it works in other apps. You end "scrollback mode" with Esc.

As for scrolling the scrollback buffer without first entering scrollback mode, that is probably not possible without modifying screen. I have never heard of a way to access the scrollback buffer, apart from scrollback mode.

Rimma answered 24/1, 2009 at 2:1 Comment(5)
Yes, I know about scrollback mode. I was hoping that I would not have to manually enter scrollback mode in order to use the mouse. Thanks.Cockloft
"Scrollback mode" is rather an unofficial term IMHO. :) Ctrl+a Esc will enter the copy mode; this mode has always been called that, as its primary purpose is to make it possible to copy text to and fro. The possibility to scroll with the mouse wheel in copy mode (nb. does not work for me) should rather be seen as a kind of "additional gimmick", but not as the main purpose of this mode.Darg
@syntaxerror: Well, the docs call it "copy/scrollback mode", and mention a "scrollback buffer" (gnu.org/software/screen/manual/screen.html#Copy-and-Paste ), so I guess we're both right :-). Anyway, I added "copy mode" to my answer.Rimma
Great! I wanted to do this too, but before messing into such old answers, I am known for asking first (even though I am aware the SO/SE rules do not prescribe it; but that's the thing with unwritten rules.)Darg
This should have been the official answer. Thank you :)Theoretician
F
26

The excellent article that Jon Z is referring to is no longer available, but I was able to fish the text-only version of it from the Google cache. I'm saving it here in case Google drops that as well in the future. Original post was by Mikael Ståldal so credit where credit is due.

--

How to use mousewheel in GNU Screen

GNU Screen has support for scrollback, but by default you have to use awkward keys to use it. I would like to be able to use Shift-PageUp, Shift-PageDown and the mousewheel to scroll, just like you can do in xterm.

It was not easy to configure Screen for this, and it involves cooperation with the terminal emulator. But I finally managed to achieve a solution which works pretty well. Add this to your ~/.Xresources file (you need to log out for this to take effect):

XTerm*saveLines: 0
XTerm*vt100.translations: #override \n\
  Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  Lock @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  @Num_Lock Ctrl <Btn4Down>: string(0x1b) string("[25S") \n\
  <Btn4Down>: string(0x1b) string("[5S") \n\
  Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  Lock @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  @Num_Lock Ctrl <Btn5Down>: string(0x1b) string("[25T") \n\
  <Btn5Down>: string(0x1b) string("[5T") \n\
  Shift <KeyPress> Prior: string(0x1b) string("[25S") \n\
  Shift <KeyPress> Next: string(0x1b) string("[25T") \n

Then add this to your ~/.screenrc file:

defscrollback 1000

# Scroll up
bindkey -d "^[[5S" eval copy "stuff 5\025"
bindkey -m "^[[5S" stuff 5\025

# Scroll down
bindkey -d "^[[5T" eval copy "stuff 5\004"
bindkey -m "^[[5T" stuff 5\004

# Scroll up more
bindkey -d "^[[25S" eval copy "stuff \025"
bindkey -m "^[[25S" stuff \025

# Scroll down more
bindkey -d "^[[25T" eval copy "stuff \004"
bindkey -m "^[[25T" stuff \004

This works in xterm. I’m not sure if it works in other terminal emulators.

Note that this disables the normal scrolling support in xterm, you will only be able to scroll when using Screen. You might want to start xterm like this to always use Screen:

xterm -e screen
Fitted answered 13/8, 2010 at 7:22 Comment(0)
P
13

And to use the scrollwheel in a VIM inside GNU Screen:

[.vimrc]

set mouse=a             " hold shift to copy xterm
set ttymouse=xterm2     " necessary for gnu screen & mouse
Phosphorescent answered 24/10, 2011 at 16:9 Comment(1)
Awesome, this in combination with the screenrc trick made my day since I use awesomewm and terminals are my lifeIrairacund
P
13

For OS X (Snow Leopard), the following worked for me:

http://slaptijack.com/system-administration/mac-os-x-terminal-and-gnu-screen-scrollback/

Briefly, it involves adding the following to ~/.screenrc on the remote host (the one you're running screen on):

defscrollback 5000
termcapinfo xterm* ti@:te@
Palatable answered 29/11, 2012 at 14:58 Comment(0)
V
11

The following worked for me in both Cygwin and Putty: Edit .screenrc and add

terminfo xterm* ti=:te=
Velocipede answered 20/1, 2014 at 13:51 Comment(1)
this approach worked flawlesslyStem
M
9

Setting TERM variable to vt100 instead of xterm before running screen also works.
I've been using this for a long time, works like a charm.

Add this to your .bashrc:

# make scrollbar / wheel scrolling work when running screen in gnome-terminal (or other)
if [ "$TERM" = "xterm" ]; then
  export TERM=vt100
fi

--

For reference, my .screenrc has this (not needed for this AFAIK):

# Extend the vt100 desciption by some sequences.
termcap  vt100* ms:AL=\E[%dL:DL=\E[%dM:UP=\E[%dA:DO=\E[%dB:LE=\E[%dD:RI=\E[%dC
terminfo vt100* ms:AL=\E[%p1%dL:DL=\E[%p1%dM:UP=\E[%p1%dA:DO=\E[%p1%dB:LE=\E[%p1%dD:RI=\E[%p1%dC
Matrimony answered 6/10, 2014 at 7:2 Comment(5)
Setting the environment variable TERM as described (before running screen) worked for me. It's as simple as keying in "export TERM=vt100". Thanks a lot. PS: I'm on a Mac, ssh into a Linux box and there I run screen.Maquis
As mentioned above this doesn't work as intended. Yes you can scroll however your scroll buffer get overridden when you change windows.Gd
very underrated solutionTricornered
Agreed @Tricornered . This is the closest thing here to a reasonable solution. This is making me want to take another look at tmux.Upend
Not perfect but it gets the job done. I think this should be the accepted answer.Boathouse
O
8

Press Ctrl+a followed by [

The title bar of your terminal should now say Copy mode.

Now the arrow keys and the mouse wheel should work as expected.

To return to normal press Esc or press Enter a couple of times.

Ombudsman answered 12/11, 2012 at 12:24 Comment(0)
S
5

The solution when using "Ubuntu 16.04.2 LTS" is as follows:

a). Update $HOME/.screenrc as previous answers have specified:

termcapinfo xterm* ti@:te@

b). Use "Settings"."Preferred Applications" to alter the default terminal to xterm, by selecting the "X Terminal" one in the drop-down list.

Some superfluous notes

  • None of the other terminals, including installing "lxterminal", worked for me, even when I altered the termcapinfo line to "*" instead of "xterm*".

  • By clicking the menu button in the top-left corner of the screen, you can get the Settings dialog using the 3rd icon from the bottom right corner.

Statesmanship answered 22/7, 2017 at 12:56 Comment(0)
E
3

If the answers above don't work for you, make sure you don't have a caption or the alwayslastline option set in your .screenrc. If you have them, this will not work:

termcapinfo xterm* ti@:te@

If you need this information, you can try setting it in the title of your terminal (with termcapinfo)

Emigrant answered 14/2, 2017 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.