In GNU screen, I want to change the default command binding to Alt-s (by tweaking .screenrc) instead of the default C-a, the reason is I use emacs hence GNU screen binds the C-a key, sending "C-a" to the emacs becomes tedious (as @Nils said, to send "C-a" I should type "C-a a"), as well as "C-a" in bash shell, and I could change the escape to C- but some of them are already mapped in emacs and other combinations are not as easy as ALT-s . If anyone has already done a ALT key mapping, please do let me know.
7 Answers
From my reading of man screen
it seems like the only meta character that screen
can use for the command binding is CTRL
:
escape xy
Set the command character to x and the character generating a literal
command character (by triggering the "meta" command) to y (similar to
the -e option). Each argument is either a single character, a two-character
sequence of the form "^x" (meaning "C-x"), a backslash followed by an octal
number (specifying the ASCII code of the character), or a backslash followed
by a second character, such as "\^" or "\\". The default is "^Aa".
If there is some mapping that you don't use in emacs, even if it's inconvenient, like C-|
, then you could use your terminal input manager to remap ALT-X
to that, letting you use the ALT
binding instead. That would be a little hackish though.
-
thanks. That's sort of tricky, perhaps there could be a direct way to do this – Siva Oct 09 '09 at 12:35
-
4You don't have to preface the escape key with Control. I use "escape `~", which sets the it to backtick (without Control). I don't think you can use Alt-anything, though. – silentbicycle Oct 09 '09 at 12:46
-
@silentbicyle thanks. yeah i know I dont have to preface with Control, "escape `~" doesn't work for me. And I ll become tedious when I have to actually ~ in any of the programs running on the shell, that is the reason why I prefer CTL/ALT mapping. – Siva Oct 09 '09 at 13:07
-
See my answer below. The "escape" command uses so-called caret notation. So you use ^G for G as the control character. The tricky part is that "escape" expects two concatenated arguments: the "controlling character" (a by default) and a meta character ([ by default) – audiodude Jul 01 '11 at 08:51
I'm an Emacs and screen user as well. Although I rarely use Emacs in a terminal -- and as such in a screen session -- I didn't want to give up C-a for the shell either (which uses Emacs key bindings). My solution was to use C-j as the prefix key for screen, which I was willing to sacrifice. In Emacs programming modes it is bound to (newline-and-indent) which I bound to RET as well, so I really don't miss it.
By the way: I know this is an advise rather than an answer, but I felt this would be valuable enough to post nevertheless.

- 2,424
- 26
- 46
It is possible to work around :escape command limitations using registers and :bindkey command. Just put this in .screenrc:
# reset escape key to the default
escape ^Aa
# auxiliary register
register S ^A
# Alt + x produces ^A and acts as an escape key
bindkey "^[x" process S
## Alt + space produces ^A and acts as an escape key
# bindkey "^[ " process S
See http://adb.cba.pl/gnu-screen-tips-page-my.html#howto-alt-key-as-escape

- 367
- 2
- 9
To make Alt+X the default prefix for commands and free C-a, add the following lines to .screenrc:
escape ^||
bindkey "^[x" command
As a side effect C-| will be command prefix too. If you need this keys to be free too, then fix "escape ^||" accordingly.
-
How does `^[x` be transfered to `Alt-x`, where `^` means `Ctrl`(I'm not sure)? Does `[` mean `Alt`? Thanks. – Leo Dec 07 '17 at 03:42
-
If you are blessed with an `Alt Gr` key (in, for example, a Latin American keyboard), you can take advantage of it as third level modifier to input a rarely used symbol which you can bind as command key. For example, with my LA keyboard in Ubuntu, I have `bindkey "ð" command` in .screenrc. So, I use `Alt Gr + d` (which sends the ð character) as my command key. – ARX Jan 26 '19 at 16:09
Screen doesn't have any shorthand syntax for alt bindings, but you can give it the octal code directly. For instance on my machine, Alt-x has the hex code F8, or 370 octal, so putting
escape \370x
in my screenrc changed the escape code to alt-X
Tested and works with screen 4.00.03 on Linux.
You may have to change the escape, since I think this may depend on things like your language and codeset, etc: how I found out what my escape code was was to type
$ echo -n ^QM-x | perl -ne 'printf "%lo\n", ord($_)'
^Q is the quoted-insert command for readline (it inserts what you type directly without trying to interpret it) and M-x was a literal Alt-X.

- 8,215
- 2
- 37
- 47
-
I have tried this trick and it doesn't work for me. Is there a way to debug this? – Siva Oct 11 '09 at 11:14
-
Hi Siva - I think the most likely difference is due to the terminal encoding of the meta keys. I'm using xterm with the xterm termcap/terminfo setting; it's possible other terminals like kterm or gnome-terminal, or different TERM settings, use a different encoding. What does my echo trick produce on your machine? – Jack Lloyd Oct 13 '09 at 10:59
Something I have had for years in my .screenrc
:
escape ^Zz
which is now hardwired in muscle memory for me.
Somehow I ended up having to share a screen with someone else's config, and now I keep stopping processes all the time (bash ^Z
)... Not funny...

- 860
- 8
- 12
Fellow emacs user here.
The best solution I've found is a ~/.screenrc file with the following:
# C-a :source .screenrc
escape ^gg
Live updated here: https://gist.github.com/1058111

- 1,865
- 16
- 22
-
btw, this works really well for me because ^G is the "cancel" sequence in emacs. So if your muscle memory 'spasms', you don't mess anything up in emacs. – audiodude Jul 01 '11 at 08:52
-
5I'm not a fan of this. C-g is one of the last keys I would want to give up in Emacs. – Psyllo Sep 22 '11 at 21:35
-
Change it to "escape ^\`[" to use backquote. C-\` is not bound to anything in Emacs by default. – Psyllo Sep 22 '11 at 21:43