How to bind ‘tab’ and ‘shift+tab’ in GNU screen

gnu-screenkeyboard shortcuts

How do I bind the keys Tab and ShiftTab in screen? My problem is that I don’t know what to pass to the screen bind command to designate these keystrokes.

BTW, I’m aware of GNU screen: move between regions but the answer is not there.

All of the following fail with the error -X: bind: character, ^x, or (octal) \032 expected:

screen -X bind "\033[Z" focus up
screen -X bind "^[[Z" focus up
screen -X bind "\t" focus up
screen -X bind \033[Z focus up
screen -X bind ^[[Z focus up
screen -X bind \t focus up

Same thing if I hit CtrlA: to input the command.

Best Answer

Contrary to bindkey where you can specify character sequences, with bind, the only way is by using bind -k CAP where CAP is a termcap key capability.

For instance,

bind -k ku focus up

works to bind the sequence of character sent upon Up to focus up. For backtab, that should be:

bind -k kB focus up

Unfortunately, for some reason, it doesn't see to work. Not sure why. My first interpretation was wrong. It sounds like it has something to do with with ncurses not handling the termcap equivalent of kcbt correctly:

$ infocmp -1 | grep Z
    cbt=\E[Z,
    kcbt=\E[Z,
$ infocmp -1C | grep Z
    :bt=\E[Z:\

(kcbt is no translated to kB).

If I add to my ~/.screenrc:

 termcapinfo * kr=\E[Z
 bind -k kr focus up

That is, if I tell screen that whatever the host termincal (*), F63 (kr) sends \E[Z, and bind F63 to focus up, then that works. However note that pressing Shift+Tab now sends within screen \EOC, which is the character sequence that the terminal emulator that screen implements (as opposed to the host terminal) sends upon F63.

Related Question