3

So ctrl page up and down are all the rage nowadays, and I'd like to be able to C-p and C-n in gnu screen when I hit ctrl-pgup and down. I've tried and tried but the documentation is a little thin. Any ideas?

4 Answers 4

5

It turns out you can do it. I finally figured it out.

With the help of this...

https://unix.stackexchange.com/questions/76566/where-do-i-find-a-list-of-terminal-key-codes-to-remap-shortcuts-in-bash

I add this to ~/.screenrc:

bindkey -t ^[[5;7~ prev
bindkey -t ^[[6;7~ next

and that gets me Ctrl + Alt + PageUp/Down moves between screen tabs.

5
  • this one is handy too. ctrl-alt t for make a new screen bindkey -t ^[^T screen
    – Stu
    Aug 1, 2015 at 15:56
  • For alt/page{up,down}, change the ;7~ to ;3~ in the snippet.
    – peterh
    Nov 7, 2016 at 0:57
  • And for Ctrl + Page[Up|Down] change ;7~ to ;5~. Oct 10, 2019 at 13:21
  • Found it, -t stands there for the key code, you can use ;2~ for the SHIFT key. Thank you!
    – linux64kb
    Jan 10, 2022 at 19:20
  • This binding scrolls between the contents of screen windows in multi window screen scenario (I guess because of the prev-next commands). If you want to scroll the contents of the actual screen windows I've found this unix.stackexchange.com/questions/46483/…
    – linux64kb
    Jan 10, 2022 at 20:57
4

A controlpageup depends upon the particular terminal, but most of the ones you are interested in copy one of the flavors from xterm. Those look like

^[[5;5~

or in terminfo format

\E[5;5~

That is 6 characters.

However, screen (see 14.1 The bind command from screen's manual) says that it only knows how to bind a single character.

So the answer is: you cannot do that with screen.

2
  • I tried some more and I think you can do it (bindkey allows multiple characters) but what I didn't realize is that ctrl-pgup/dn never make it to the terminal because my xfce terminal grabs them for itself.
    – Stu
    Jul 28, 2015 at 18:04
  • See my answer, you can...
    – Stu
    Jul 31, 2015 at 23:58
3

You can define it easily using the bindkey command:

bindkey -t <key-code> <command>

It allows you to map any key to any command. For switching to the previous and next window, use commands prev and next.

The key code for PageDown is ^[[5~ and PageUp ^[[6~, so to switch windows using those two keys, add the following to your ~/.screenrc configuration:

bindkey -t ^[[5~ prev
bindkey -t ^[[6~ next

To add the Ctrl modifier, add ;5 to the key code:

bindkey -t ^[[5;5~ prev
bindkey -t ^[[6;5~ next

For the Alt modifier, add ;3 and for Ctrl + Alt, add ;7.

The -t parameter disables the timer so there may be a time gap between the presses of the individual keys.

Finding Out Key Codes

It's possible that on different systems or terminals, key codes may be different. To find out the exact codes, execute showkey -a and press the keys or key combinations of your interest, the program will print their codes in the first column.

1
  • I've spent some minutes pressing ALT, SHIFT, CAPS, CTRL to no result ... ENTER and other keys worked though. Don't forget to press PgUp or PgDn in conjunction with these keys :rotfl: anyway, here is the list of codes I've amassed # ;2~ stands for ANSI SHIFT # ;3~ stands for ANSI ALT # ;4~ stands for ANSI SHIFT+ALT # ;5~ stands for ANSI CTRL # ;6~ stands for ANSI CTRL+SHIFT # ;7~ stands for ANSI CTRL+ALT # ;8~ stands for ANSI CTRL+ALT+SHIFT
    – linux64kb
    Jan 10, 2022 at 20:41
1

The title text in the question asks about ctrl+pageup and ctrl+pagedown, but the selected answer mentions alt+ctrl. Here's how xterm reads ctrl+pageup and ctrl+pagedown.

in ~/.screenrc:

# ctrl+pgup = prev
bindkey -t ^[[5;5~ prev
# ctrl+pgdn = next
bindkey -t ^[[6;5~ next
3
  • if you look down a few answers somebody pointed out you can't do that with screen, so I came up with something that yields a usable result with ctrl-alt which I could do with screen
    – Stu
    Aug 21, 2019 at 1:43
  • @stu What version of gnu screen are you using? And what terminal? I use this on multiple different computers, copied from my ~/.screenrc, and it works fine.
    – BurnsBA
    Aug 21, 2019 at 12:30
  • whatever comes with ubuntu 1604. if I remember right, it might not be screen as much as the terminal I'm using that grabs the keystrokes before they get to screen.
    – Stu
    Aug 23, 2019 at 0:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .