1

I'm running Linux in single user text mode (as described here). Ctrl+PgUp and Ctrl+PgDn don't behave as expected. Using cat -v - to show the terminal codes, I see that PgUp and Ctrl+PgUp both produce the same code ^[[5~. Doing the same thing in graphical mode I see PgUp => ^[[5~ and Ctrl+PgUp => ^[[5;5~ (and both keys work as expected). Therefore I conjecture:

  • It's not a hardware problem
  • The mapping PgUp => ^[[5~ is working as intended
  • The problem is that Ctrl+PgUp looks like PgUp once it reaches the terminal.

For my use case (Vim) I can configure PgUp to be treated as Ctrl+PgUp, but if possible I'd like them to have different behaviours.

Is there some configuration I can edit to fix this? Does anything modify the character sequences before they reach the terminal?

More notes from further investigation:

  • Rather than booting to text mode, I can reproduce this just by dropping to tty1 (Ctrl+Alt+F1).
  • I can reproduce it on a different machine.
  • Following dirkt's suggestion I ran echo $TERM and got linux.
3
  • 1
    On my console, the terminal type is linux (echo $TERM), and infocmp linux shows that knp (next page) and kpp (previous page) are bound to ESC [ 6 ~ and ESC [ 5 ~, respectively. So this is a "feature" of the linux text console, though I am not sure exactly which level is responsible, and how to configure it. Maybe trying to configure vim to recognize the escape sequences is simpler.
    – dirkt
    Aug 8, 2017 at 9:19
  • @dirkt Thanks for the comment; I didn't know about infocmp. However I think the problem is not what PgUp maps to, but that PgUp and Ctrl+PgUp are indistinguishable. I'll make an edit to clarify.
    – stewbasic
    Aug 8, 2017 at 21:39
  • They are likely indistinguishable because the linux text console translates both to knp and kpp. You can easily check the lowest layers with evtest, and my guess is that the Ctrl key will be clearly visible, and the translation happens after the keyboard events leave the kernel input layer and enter the console line discipline (or whereever that translation actually sits).
    – dirkt
    Aug 9, 2017 at 4:41

1 Answer 1

1

This useful answer led me to a solution. My default keymap (obtained from sudo dumpkeys) contained

keycode 104 = Prior
...
string Prior = "\033[5~"

I added

control keycode 104 = F105
...
string F105 = "\033[5;5~"

and similarly for PgDn. Note that the alias can't be an arbitrary string; it has to be one of the keysyms listed by sudo dumpkeys -l, so I picked F105 which was unused.

Now cat -v - shows ^[[5;5~ for Ctrl+PgUp as in graphical mode. Vim still didn't react as expected (I'm not sure why, since it works in graphical mode) but at least Ctrl+PgUp produces a different control sequence from PgUp, which I remap in my .vimrc as usual:

nnoremap ^[[5;5~ :tabp<Enter>

You must log in to answer this question.

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