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
Hi. This simple line in .screenrc works for me in konsole (Kubuntu 8.04):
termcapinfo xterm|xterms|xs|rxvt ti@:te@
@Saul That doesn’t work when you are swapping back and forth between multiple screen windows. All of the output from those screen windows gets jumbled together in the xterm scrollback buffer. Screen has it’s on per-window scrollback buffers that are kept separate though. This enables you to use the screen scrollback buffers instead of the xterm one.
Awesome! I can confirm this works on ubuntu, still not sure how to achieve this effect on OSX.. all that Xresources stuff is total voodoo to me.
Whoa…. it would be cool to get it working under OSX… I’ll try it out this weekend
Cool! It really works! Could you suggest same hack for rxvt-unicode?
Sorry, I have never used rxvt.
more useful tips regarding this here:
http://stackoverflow.com/questions/359109/using-the-scrollwheel-in-gnu-screen