Using the scrollwheel in GNU screen

2019-01-29 14:51发布

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

10条回答
爷的心禁止访问
2楼-- · 2019-01-29 15:09

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@
查看更多
聊天终结者
3楼-- · 2019-01-29 15:14

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

terminfo xterm* ti=:te=
查看更多
三岁会撩人
4楼-- · 2019-01-29 15:14

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.

查看更多
倾城 Initia
5楼-- · 2019-01-29 15:15

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
查看更多
Viruses.
6楼-- · 2019-01-29 15:21

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
查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-29 15:28

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
查看更多
登录 后发表回答