views:

1076

answers:

4

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.

A: 

Doesn't answer your question, but C-a a does send C-a to the window, does it not ?

Nils
It does, it's just less convenient for emacs users.
rampion
C-a does it. But the problem is I cant use the C-a binding in emacs running on screen. Hope you got it
Siva
@rampion: Got that, but the question stated "I cant use C-a in emacs", which I belive is wrong.@Siva: Hm. acually, no. Pressing "C-a a" sould send C-a to emacs. It it inconvinient, yes - but possible.
Nils
@Nils yep, you are correct, I should reformat the question.
Siva
+2  A: 

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.

rampion
thanks. That's sort of tricky, perhaps there could be a direct way to do this
Siva
You 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
@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
+2  A: 

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.

Jack Lloyd
I have tried this trick and it doesn't work for me. Is there a way to debug this?
Siva
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
A: 

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.

paprika