screenrc: How to map "alt+number" to “select a screen window” in gnome terminal

3

1

I found this online:

bindkey "\261" select 1
bindkey "\262" select 2 
bindkey "\263" select 3 
....

Basically it maps alt+1 to "select 1"; alt+2 to "select 2". So when you press alt+1, it is supposed to jump to screen window 1.

This works in xterm but not but in gnome-terminal. I know gnome-terminal already uses alt+N to switch to tab n. So I turned off this key mapping for gnome terminal in gnome configure editor. But it still doesn't work.

Seems that when I press alt+1, it is received by bash, not by the GNU screen program, so it puts a special character on the bash or puts "arg: 1".

Any solutions? Thanks a lot!

vim

Posted 2011-06-10T18:23:24.710

Reputation: 33

Answers

4

The problem is caused by different treatment of the Meta key (Alt on PC keyboards) by Xterm and GNOME Terminal.

In Xterm, holding the Meta key will (by default) set the highest bit on the characters (Meta+1 becomes \261), while GNOME Terminal and most other terminal emulators leave the character unmodified but prefix it with an ESC (the same keypress becomes \033\061).

There doesn't seem to be a way to configure the handling of Meta key in GNOME Terminal (printf '\033[?1036l' may work, but I cannot test it), so you will have to somehow bind \033\061 to "select 1" and so on. (It's highly unlikely that it'll actually work, and if it did, it would probably break every other special key out there: arrows, function keys, etc.)

user1686

Posted 2011-06-10T18:23:24.710

Reputation: 283 655

HI grawity, it works when binding "\033\061" to "select 1". Awesome!!! Thank you so much. Right now, it doesn't break anytings like arrows or function keys. let's see. Again, many thanks! – vim – 2011-06-10T20:26:00.597

1The reason that GNOME Terminal and most other terminal emulators these days encode Alt as an ESC prefix is that setting the Meta bit collides with character encodings beyond 7-bit ASCII. – ak2 – 2011-06-12T07:17:16.983

Hi ak2, Thanks for commenting the reason. – vim – 2011-06-13T17:15:46.703

grawity is right, the binding is breaking some things, for me I cannot type Chinese character 花 anymore. – gb. – 2012-01-06T10:06:31.320