Home » Questions » Computers [ Ask a new question ]

What's the least conflicting prefix/escape sequence for screen or tmux?

What's the least conflicting prefix/escape sequence for screen or tmux?

Screen goes with Ctrl+A. tmux on the other hand—as developed within screen—uses Ctrl+B. Both keystrokes, however, are also used in editors, shells, etc. Thus choosing either one degrades the user experience and functionality of those tools when used within tmux or screen.

Asked by: Guest | Views: 108
Total answers/comments: 5
Guest [Entry]

"I think ^\ (a.k.a. ^|) is the best if it's in a convenient position on your keyboard layout. Its uses in other programs are quite rare:

sending SIGQUIT to a process
aborting for or while loops in a shell when ^C is intercepted
toggle-input-method in emacs

I don't know of any other uses. Be careful to not accidentally kill a processes outside of tmux or screen after getting used to it. It happened to me only once in a few years though.


unbind-key C-b
set -g prefix 'C-\'
bind-key 'C-\' send-prefix


escape ^|^|"
Guest [Entry]

"Ctrl+A is also known to cause problems with Emacs, including Bash in Emacs mode. It sounds like this is not a problem for you.

Ctrl+O is the other option I've seen. Apparently, this is the default in RatPoison (this is an X window manager that doesn't need a mouse). I've used Ctrl+O when using nested screens: Ctrl+O for the outer one and Ctrl+A for the inner ones. Worked well, but kinda scared my colleagues. :-)

I was just thinking and if you use vi rather than Emacs, there are a few alternatives. Ctrl+G isn't used by much, for instance."
Guest [Entry]

"I use a complex system for screen. My default escape is set to \140\140, which is backtick. The Ctrl-A complicates both Emacs and command line editing for me within Zsh, and I dislike Ctrl-O (2 hand operations for most screen actions).

I rebind 's' to screen 1 so that new sessions are created from left to right on the keyboard starting at 1. This allows me to reserve screen 0 for what I consider persistent or reference windows. It's very quick one handed gesture to (backtick)1, (backtick)2, (backtick)3 to swap between windows.

The issue with using backtick in a Unix environment is when attempting to cut-and-paste shell/Perl script code. For this reason I bindkey F11/F12 to switch between my escape character.

bindkey -d -k F1 escape ^O^O # bound to F11
bindkey -d -k F2 escape \140\140 # bound to F12

This will swap the escape to Ctrl-O for when I'm doing cut-and-paste operations. I've found hitting a double tick is simple, and a good trade off for most screen operations.

Revisiting this answer with a newer solution that allows for toggling the mode by hitting F12, and using a caption to indicate mode.

## command characters
escape \140\140 # default is `

## sets caption and escape toggle
bindkey -d -k F2 process a # bound to F12

## initial caption
caption always '%{= kW}%?%F%{+b KW}%:%{= kK}%? %= %?%F%{-b .c}>>>%{-}%? | %-w%{mW}%n* %t%? @%u%?%{-}%+w '

## registers to toggle bindkeys
register a ""\140:eval 'bindkey -d -k F2 process b' 'process c' 'escape \\017\\017'^M""
register b ""\017:eval 'bindkey -d -k F2 process a' 'process d' 'escape \\140\\140'^M""

## registers to change captions
register c ""\140:caption string '%{= kW}%?%F%{+b mW}%:%{= kK}%? %= %?%F%{.c}ALT%{-}%? | %-w%{KW}%n* %t%? @%u%?%{-}%+w '^M""
register d ""\017:caption string '%{= kW}%?%F%{+b KW}%:%{= kK}%? %= %?%F%{.c}>>>%{-}%? | %-w%{mW}%n* %t%? @%u%?%{-}%+w '^M"""
Guest [Entry]

"I like to reserve ^Space for very special/common operations because I find it to be the easiest prefix to type, but right now I'm trying it mapped as the prefix in tmux.

It leaves your fingers free to instantly jump to the command you want to type. Give it a try."
Guest [Entry]

"A belated suggestion: ctrl-s. ctrl-s has a number of advantages:

On the home row.
Still close to ctrl-a (in fact, for most typers it will use the same two fingers they used for ctrl-a), so the muscle memory switch from ctrl-a to ctrl-s is trivial -- for me, it became second nature within about an hour of first trying it.
Frees up ctrl-a for emacs-style ""back to beginning of line"" or vim-style ""increment number"" operations. Or hey, for running screen inside a tmux pane without needing to worry about escaping prefix characters to control the embedded screen instance. (I often do this using a local tmux with panes containing ssh sessions to remote servers, in which I run screen)
Doesn't override or add escaping-requirements to any other commonly-used terminal functionality. nothing the vast majority of people use today is on ctrl-s!

Of course, the reason that nothing is on ctrl-s is that in the terminal, it traditionally is used for flow control, dating back to the days before paging tools like more and less were common. I'm sure some GUI terminal program somewhere still has that flow-control functionality enabled by default, but I haven't actually bumped into one; the gui terminal programs I've tried all seem to completely ignore it by default, which makes that convenient key combination available for more productive uses.

So if you're not actually using screen/tmux from within (for example) a raw Linux terminal, but rather from a GUI-based terminal, then I recommend giving ctrl-s a try; it's made zipping about in tmux and screen a lot more convenient for me."