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)

6 Answers6

45

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.

Nifle
  • 34,998
skyshock21
  • 551
  • 1
  • 4
  • 3
20

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
Chris Johnsen
  • 42,029
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.

MikeHoss
  • 307
2

I use this .screenrc

escape ^bb

Example: To detach you type ctrl-b d

guettli
  • 397
  • 3
  • 8
  • 26
0

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

graywh
  • 197
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).

Arcege
  • 2,163