4

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.

  • @StephaneChazelas I would agree, except that: 1) other people might find this question useful if they're looking for this particular case; 2) I still couldn't find exactly what to pass to bind to make this work - see (upcoming) edit – ricab Oct 25 '13 at 13:52
  • OK, retracting the close vote since it's a newer question now. Unfortunately, the way SE works, unless all the other closers retract their close votes, it's likely to end up being closed... – Stéphane Chazelas Oct 25 '13 at 14:37
  • Please reopen, that was me closing it by mistake. – Stéphane Chazelas Oct 28 '13 at 15:12
  • @StephaneChazelas: something I should do to reopen? – ricab Oct 28 '13 at 16:16
  • Nope. Wait for enough people with enough reputation to vote for reopen, like for the closing. – Stéphane Chazelas Oct 28 '13 at 17:31
2

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.

  • I didn't quite get this answer and it didn't work for me. bind doesn't have a -k option here (at least not documented). I get also "character, ^x, or (octal) \032 expected" with your bind cmds. But thanks for the help anyway – ricab Oct 28 '13 at 14:02
  • OK I figured you probably meant bindkey instead of bind. Tried that and it now Shift+TAB does focus up. But not after Ctrl+A as with tab, so it is still no symmetric. I basically wanted to have C-a shit-tab be the symmetric of the default C-a tab – ricab Oct 28 '13 at 14:09
  • 1
    @ricab, bind -k works for me though it's not documented (4.01.00devel) – Stéphane Chazelas Oct 28 '13 at 15:11
  • Interesting, it does not work here (4.00.03 (FAU)). I get the error bind: character, ^x, or (octal) \032 expected – ricab Oct 28 '13 at 16:19
  • 1
    regarding "(kcbt is no translated to kB)." -- that's probably because the termcap was trimmed to fit in 1023 bytes (expected behavior). – Thomas Dickey Dec 20 '18 at 2:24

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.