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

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.

| improve this answer | |
  • 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 '15 at 18:04
  • See my answer, you can... – Stu Jul 31 '15 at 23:58
4

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.

| improve this answer | |
  • this one is handy too. ctrl-alt t for make a new screen bindkey -t ^[^T screen – Stu Aug 1 '15 at 15:56
  • For alt/page{up,down}, change the ;7~ to ;3~ in the snippet. – peterh - Reinstate Monica Nov 7 '16 at 0:57
  • And for Ctrl + Page[Up|Down] change ;7~ to ;5~. – David Ferenczy Rogožan Oct 10 '19 at 13:21
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
| improve this answer | |
  • 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 '19 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 '19 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 '19 at 0:27
0

You can define it easily using the bindkey command:

bindkey -t <key-code> <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, use 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 presses of the individual keys.

It's possible that on different systems or terminals, key codes may differ. Use showkey -a to find out the exact codes.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.