3

I'm having a hard time finding a "command character" for GNU-screen that does not collide with some key combination that I already use.

Through Emacs (and org-mode, and my regular shell, etc.), pretty much all the command characters consisting of Ctrl + [A-Z] are off-limits.

I figure that, if there were a simple, and consistent, way to type any one of the characters in the ASCII range 27 through 31, that may do the trick.

Are there any tools I could use to find a way to type one of these characters that fits the above criteria?

(BTW, by "consistent" I mean that it can be typed the same way in "all keyboards", or at least in "all US keyboards".)

1
  • You can still use the screen's metacharacter in your terminal; by default, ^A-a is a literal ^A sent to the terminal session. That said, you should be able to use the -e option to set both the override command signal and the command to send it as a literal. (-e^Aa is the default, for example).
    – DopeGhoti
    Commented Nov 20, 2015 at 18:12

3 Answers 3

3

You can use any function key that Screen recognizes as the escape character. Set the escape character (more precisely, the escape byte) to one that you never type, for example \377 which is never used by UTF-8. Bind the key you want to use as the escape key to command, for example F12 (which is F2 in termcap speak — see the section “Input translation” in the Screen manual):

escape \377\377
bindkey -k F2 command

You aren't limited to keys for which Screen knows a symbolic name. To set an arbitrary key or keychord as the command key (the key does need to send an escape sequence in the terminal), find out what escape sequence it sends by pressing Ctrl+V then that key at a shell prompt. This causes the escape sequence to be inserted literally, instead of being recognized by the shell as an escape sequence. For example, if you wanted to use F12, you could press Ctrl+V then F12, which inserts ^[[24~ (the first ^[ represents the escape character) (some terminals may send a different escape sequence); then you would use

bindkey ^[[24~ command

I use Ctrl+\ as my Screen escape key (escape ^\\\), and let Ctrl+\ \ inject a ^\ character. Few programs use the ^\ control character. In Emacs, it calls toggle-input-method, which I don't use; your mileage may vary. In a cooked terminal, it sends SIGQUIT, which is rarely useful (when it's needed, Ctrl+Z followed by the kill command usually works as well; I default to having core dumps disabled). Ctrl+\ can be difficult to type on some keyboard layouts where \ requires AltGr, but on the US layout it's straightforward. I also configure my terminal emulator to send the ^\ character when I press Ctrl+`, which lets me type it with the left hand as well.

Ctrl+] (Emacs: abort-recursive-edit) and Ctrl+^ (Emacs: undefined; but it's awkward to type on a US keyboard as well as on many other layouts) are other likely candidates for an Emacs user.


By the way, if you only use Screen to run Emacs and some shells, you don't need Screen. Emacs can play the same role. Keep a single Emacs process running, and use emacsclient to open a window on this Emacs process from any terminal. If the terminal goes away, you can run emacsclient again to connect to the same Emacs instance. You can have as many instances of emacsclient as you like that are connected to the same Emacs instance, possibly displaying through different local and remote connections.

To start Emacs with no interface, run emacs --daemon. Then run emacsclient -c to open a window to the existing Emacs instance (or emacsclient -c -nw to force a text mode window). If you want to start Emacs if it wasn't already started but connect to the existing Emacs instance if there is one, run emacsclient -a '' -c.

If you want to run shells, you can use M-x shell or M-x term or the like inside Emacs. Emacs can do pretty much everything Screen can do.

6
  • Thanks! I realize that there are many key combinations that wouldn't interfere (too much) with Emacs. (My favorite among them, in fact, would be <kbd>Ctrl</kbd> + <kbd>'</kbd>, if I could hack it.) My difficulty is not knowing how to translate those possibilities into directives to put into .screenrc... Let me ask you: What do you put in your .screenrc file in order to get <kbd>Ctrl</kbd> + <kbd>\</kbd> as your screen character key? Also, I take it that in the example you gave the intent is to make the <kbd>F12</kbd> key the character key?
    – kjo
    Commented Nov 21, 2015 at 1:37
  • 1
    @kjo Edited. There's no Ctrl+' character, so Ctrl+' sends ' in most terminals; see emacs.stackexchange.com/questions/1020/… for how to make it send an escape sequence in xterm, but I'm not sure if you can use that escape sequence to bind it to command, I think Screen is limited to keys defined by termcap. Commented Nov 21, 2015 at 12:48
  • Thank you for the edit, and your very helpful comment. My reply to the latter grew too big to be a comment, so I posted it as a separate question.
    – kjo
    Commented Nov 23, 2015 at 14:50
  • I've also been using ^` as my screen escape for decades. The default ^A` always seemed crazy (I can only assume that the original author didn't use Emacs).
    – Barmar
    Commented Nov 23, 2015 at 16:00
  • @Barmar: thanks! Based on what I've learned so far, I would have not expected ^` to be suitable for this, since it is not a bona fide "control character" (the second character in the "key chord" is neither a letter nor one of @ [\]^_?). Does ^` work for you "out of the box", i.e. without any additional config? If yes, how did you know ahead of time that ^` would work (considering that, as already mentioned, it is not a "control character"). If, on the other hand, you did require an additional config for ^` to work, would the analogous config get ^' to work?
    – kjo
    Commented Nov 23, 2015 at 21:36
0

I use Meta-a for screen, because all the control characters are already in use by my applications. To do this, I put my xterms into 8-bit mode (UTF-8 encoding disabled, LANG=C), and put

escape "<E1>a"

in my ~/.screenrc, where <E1> is the byte hex 0xe1 (i.e., lower-case a with the high bit set for escape, and a plain a to send a meta-a).

This is not so good if you care about UTF-8 in your xterms, but works fine if you are okay with plain 8-bit.

0
0

I personnally use Ctrl-J for GNU screen for 2 reasons:

  • it is usually bound to the return key, so not very used,
  • your finger is normally located there if you are a touch typist.

    escape ^Jj

1
  • Ctl-J is used in most Emacs programming modes as the newline-and-indent command.
    – Barmar
    Commented Nov 23, 2015 at 16:01

This site is temporarily in read-only mode and not accepting new answers.

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