Binding arrow keys in GNU Screen
I'm a newcomer to GNU Screen and so far I'm liking it. However there is something I can't quite get to work the way I could in tmux.
I want to make it so that Ctrl-a "arrow key" changes focus between my windows. I typically have many splits in my terminal window.
I've searched around but been unable to find a config that works. Note I do not want to switch between windows, just the focus.
Bonus points if someone could explain the difference between "bind" and "bindkey" to my addled brain.
Cheers
Since :bind
will not accept weird virtual characters like the arrow-keys — only keypresses that have ASCII-codes or stuff like ctrlthingThatHasAsciiCode — I think using :bindkey
is the simplest way to get what you're after. For me, the following worked under GNU screen 4.06.01 in xterm and could be added either into "~/.screenrc" (affects just you) or "/etc/screenrc" (meant to apply system-wide):
# ctrlA then right-arrow-key jumps active cursor one pane to the right:
bindkey "^A^[OC" focus right
# ctrlA then left-arrow-key jumps active cursor one pane to the left:
bindkey "^A^[OD" focus left
# ctrlA then up-arrow-key jumps active cursor one pane above current:
bindkey "^A^[OA" focus up
# ctrlA then up-arrow-key jumps active cursor one pane below current:
bindkey "^A^[OB" focus down
Depending on your terminal and settings, the codes you need to place after the "^A" may be different for you. To determine what these codes are, I prefer to use vim
; open it and then press i to enter edit-mode, then press ctrlv to take raw input, then hit the key or key-combination in question * **.
When you use my approach, you'll need to type your ctrlarrowKey command fairly swiftly; screen
stops listening for custom bindings if you pause for too long between keystrokes. If it's expiring too quickly, use :bindkey -t
instead of :bindkey
to disable the timer.
* Note that unlike in vim
, screen will not like it if you insert the actual metacharacter escapes into ".screenrc" or other files you might source; simply use literal, individual '^' and '[', not the weird combined version that vim
can output (at least, that seemed to screw things up for me).
** Some people determine special key-codes by running cat
(by itself) in the terminal, and then pressing the key(s) in question (before using ctrlc to quit). I don't use this approach so YMMV.