How to change the escape key (^A) in screen without typing it

This blog post explains how to change the escape key (Ctrl-A by default) in an instance of GNU Screen if you are unable to type that key (possibly because of a malfunctioning terminal emulator).

To change the escape key to Ctrl-B, run this command (without the leading $) within the screen you want to affect:

$ screen -S "$STY" -X escape "$(perl -e 'print"\cB"x2')"

You can change back to Ctrl-A by changing the \cB in the code above to \cA. Other escapes such as Ctrl-W and even Ctrl-C also work.

You can also change the escape key remotely (i.e. on the same machine, but outside the screen) by specifying the PID or the name or both (of the form PID.NAME) of the screen to affect instead of $STY above. Use

$ screen -list

to obtain the list of PIDs and names of currently running screens. If you have given your screen session the name foo by starting it as

$ screen -S foo
, then the command to change the escape key to Ctrl-B is the following:
$ screen -S foo -X escape "$(perl -e 'print"\cB"x2')"

All these changes take effect immediately.

No comments: