How to scroll in GNU Screen
GNU Screen is great. But, after half a year of using it, I've only now figured out how to scroll into screen's buffer (courtesy of this tutorial). Normally, I just use SHIFT+PGUP to scroll up in urxvt's buffer. However, if I have two regions in screen, this doesn't work. To scroll in screen's buffer, I need to enter "copy mode". To do this, type C-a [ or C-a ESC. (The latter option works great for me because I bound the prefix key to the backtick key instead of C-a.) Once in "copy mode", I can scroll using the arrow keys or PGUP/PGDOWN keys. To exit "copy mode", I press ESC. Scrolling within screen's buffer instead of urxvt's also prevents me from losing my place in my scrollback buffer when I switch screen "windows" (terminal sessions).
Other useful commands¶
C-a Ssplits into two regionsC-a tabswitches input focus to the next regionC-a Xkills the current regionC-a :resize numlinesresizes the current region to numlines lines.
Custom key bindings for scrolling (updated 2009-04-01)¶
If you don't want to hit C-a ESC PGUP everytime to page up, you can create keyboard shortcuts. I use CTRL+K to scroll up one line and META+K to scroll up one page (I know these are kind of weird key combinations). To create these shortcuts, I put the following in my .screenrc.
bindkey "^[k" eval "copy" "stuff ^b" # enter copy mode and move up one page bindkey "^k" eval "copy" "stuff k" # enter copy mode and move up one line bindkey -m "^[k" stuff ^b # move up one page bindkey -m "^k" stuff k # move up one line
Now, when I'm in screen and press M-k, screen enters copy mode and scrolls up one page. Likewise, C-k enters copy mode and scrolls up one line. As before, to exit copy mode, hit ESC.
How to copy and paste in screen (added 2010-02-03)¶
Thanks to this GNU Screen cheat-sheet.
- Enter scrollback mode using
C-a [orC-a ESC - Press the space bar to begin selecting text.
- Move the cursor using h,j,k,l,C-b,C-f or arrow keys/PGUP/PGDOWN
- Hit the space bar again to copy the selected text.
- Hit
ESCto exit scrollback mode. - Press
C-a ]to paste.
How to open 2 terminals connected to the same session (Multi display mode) (updated 2012-04-05)¶
The -x option can be used to attach multiple terminals to the same screen session. Pretty cool! Open a terminal and create a screen session named "local"
$ screen -S local
Start a second terminal, then attach it to the existing session:
$ screen -x local
How to eliminate apparent delay when entering copy mode (updated 2012-04-05)¶
To get rid of the apparent delay when entering copy mode, I set msgminwait to 0 in my ~/.screenrc
msgminwait 0
My ~/.screenrc on github¶
Here is my ~/.screenrc on github.
See also¶
See also my post, How to start a long-running process in screen and detach from it and some "screen vs. tmux" links in the comments.
