48

I'm a new user to GNU Screen. I've been using Bash for a very long time, and I want to give GNU Screen a try.

As you know, GNU Screen uses 'C-a' (Control-A) as as the command character. Trouble is, this interferes with the Line Editing feature in Bash (and GNU Readline), because Control-A in Bash will Move to the start of the line."

I know I can set the Command Character to another key sequence, like "^Q" or "``" (Backtick), but I have trouble finding another key sequence which isn't already in use (^Q is used by the terminal, backtick is used when writing shell scripts). It appears that the Command Character may only be one or two characters in length. Can I set the GNU Screen control character to be something like "Control-Shift-A"?

(I can't use more then one hyperlink yet, so I cannot link to the Bash documentation)

3
  • 5
    For the sake of not getting disoriented when using screen on other systems, you might be best off to stick with the default keybindings, or at least to learn them first. ^A a will, by default, send the usual ^A key combo. It is a bit inconvenient if you use that combo a lot; I usually use the HOME key instead because of this. But then that doesn't always work either.
    – intuited
    Jul 6, 2010 at 2:14
  • No love here for Ctrl-space. Works great.
    – Wildcard
    Aug 24, 2019 at 1:15
  • So tragic that GNU Screen is so incredibly hostile to GNU Emacs by default.
    – ctpenrose
    Oct 17, 2022 at 3:57

6 Answers 6

19

The problem with Control-Shift-A is that most terminal emulation programs do not send a different code for it from the one sent by Control-A, so there would be no way for screen to tell the difference.

You might be able to use C-q if you do stty -ixon to disable “software flow control” on the tty. I usually do this so I can use C-s to search on the command line.

You might consider C-^, since it seems to be usually unbound. It is Control-Shift-6 on US keyboard layouts, but it may be difficult to type on other layouts.

Most people never use the tty control character C-\ to send SIGQUIT. To use it, disable the tty functionality with with stty quit undef and bind it as your prefix key. This is a bit risky though, since if you hit C-\ on a tty where the quit key has not been disabled with stty, you might kill the foreground process instead of activating screen.

I switched to tmux a while ago. Its default is C-b because it was developed under screen and did not interfere with screen's default. I have found that C-b works fairly well for me (I usually use the arrow keys for single character movement on the shell command line—though I use M-b and M-f to move by words).

Incidentally, the author of tmux uses C-a in his primary sessions and always types C-a twice (whether in a tmux session or not). If you are willing to adopt this habit, it seems like a decent compromise since the second C-a should be a no-op in most Emacs-like editing contexts. It would not work so will if you often use programs/contexts outside of screen where the second C-a would not be a no-op.

By default, C-a C-a is bound to the other command (switch to most recently active screen) in screen. To have C-a C-a send an actual C-a and have C-a o switch windows, put the following in your .screenrc:

escape ^A^A
bind o other
3
  • 2
    This sounds good, then I realized that in GNU Screen, typing C-a twice will toggle to the window displayed previously. Maybe I can map "C-a C-a" to something else, although I'm not really sure how to do that (Looks like I need to specify 'escape xy' or 'meta' for this) See gnu.org/software/screen/manual/screen.html#Other-Window May 18, 2010 at 23:32
  • 1
    @Stefan Lasiewski: Oops, I forgot that C-a C-a does not send C-a by default. See the addition at the end of the answer for a bit of configuration that makes C-a C-a send C-a and C-a o switch to the previous window. May 19, 2010 at 4:22
  • Works great! C-a C-a will send an actual C-a to the underlying shell and C-a o' will switch to the 'other' window. To send 'C-a' to Bash, hit 'C-a' twice. This should be a no-op outside of screen, and shouldn't cause problems. May 19, 2010 at 17:53
44

No need for the workaround.
To move to the beginning of the line while using screen in bash, use

Control-A (release and then) A


In general, if there's a screen control character conflicts with a bash shortcut, the bash shortcut's first Control will be replaced with Control-A

Likewise for other line editing shortcuts.

2
  • 1
    thanks, i did not now this, even though it's that easy. indeed no need to reconfigure anything. i like your answer best.
    – harald
    May 16, 2011 at 15:31
  • +1 ty - this is, by far, the best option. Funny thing is, while trying this out, I hit C-a C-a by accident and found yet another great combo.
    – kfmfe04
    Feb 19, 2013 at 2:13
4

I use C-\ for Screen and I can't recommend it enough. You may hit any other key definition on accident but not generally C-\ . That's what I like about it.

2

I use this .screenrc

escape ^bb

Example: To detach you type ctrl-b d

0

I use ctrl-_ (which can also be produced by ctrl+7 and usually ctrl+/) with screen/tmux.

0

I use ctrl-z most of the time, but also use ctrl-x for some. I don't use the 'stop' interrupt that much, but when it is needed, I can type ^zz. This also allows me to start secondary screen sessions on remote servers that use the default ctrl-a. And if I start a third session (on a third server), then I can use ctrl-x. Ctrl-x is the lockscreen function, which in many environments is not all that usual (since screen is often running inside a terminal emulator).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .