What's the least conflicting prefix/escape sequence for screen or tmux?
Solution 1
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.
~/.tmux.conf
unbind-key C-b
set -g prefix 'C-\'
bind-key 'C-\' send-prefix
~/.screenrc
escape ^|^|
Solution 2
For people who want to use backtick as the escape in tmux, you'll want to add:
unbind C-b
set -g prefix `
bind-key ` send-prefix
That last one is important, else you can't type a backtick for other purposes :-)
Solution 3
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.
Solution 4
I've got CAPS-LOCK
globally mapped to ESC
. Then, I use M-Space
(ie. CAPS-LOCK
+ Space
) for my prefix.
Solution 5
I use Ctrl-Q
in tmux
and it has worked well so far. I have to mention, though, that it conflicts with shell flow control. By default, Ctrl-Q
is used to re-enable output after stopping it with Ctrl-S
. Having been surprised by a stuck shell a few times after accidentally hitting Ctrl-S
, I have learned not to press Ctrl-S
.
(One could also turn off flow control altogether with stty -ixon
, or bind different keys to stty start
and stty stop
.)
# tmux.conf
unbind C-b
set -g prefix C-q
Related videos on Youtube
Flow
Updated on September 17, 2022Comments
-
Flow over 1 year
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.
What prefix conflicts the least with other programs' and shells' keybindings?
-
iconoclast over 8 years"which one conflicts least with other programs?" has nothing to do with opinion.
-
ks1322 over 8 yearsAfter changing
~/.tmux.conf
don't forget to restart tmux server for changes to take effect (superuser.com/q/188491/105108). -
cjay over 5 yearsAlternative to using a prefix: Some terminals now offer tmux integration via "tmux -CC" (i.e. iTerm2 for macOS). That way tmux windows appear as tabs in the terminal. You could then use key bindings for managing tabs that don't conflict with any terminal program, i.e. by using the cmd key (aka super key, windows key).
-
-
quack quixote over 14 yearsindeed, i use the default (in screen, never tried tmux) and haven't yet found a need to change it.
-
Flow over 14 yearsFor Emacs users Ctrl+O seems to be the the best pick: In emacs it´s only "open a new line at the cursor" and in bash "repeate a command sequence".
-
DaveParillo over 14 years+1 if you are OK with right handed ctrl-operations, this looks like a good backup. I'm a lefty myself ;-)
-
staticsan over 14 yearsCreative solution. I'm impressed.
-
terrace over 13 yearsThat didn't last long – I'm back to ^j. ^Space is too similar to commands that I use to invoke OSX-level apps (Spotlight, QuickSilver, DTerm).
-
James Bay about 13 yearsHow can you define backtick for tmux?
-
jmhmccr about 13 yearsSomething like: unbind C-b; set -g prefix '
'; bind '
' send-prefix; see Darren Hall's answer above. -
Flow about 12 yearsPlease don't refer to answers as "above" and "below" as the order could change. Link the answer instead. Thanks for your answer :)
-
WildTigerrr about 12 yearsbind-key -n F11 set -g prefix ` bind-key -n F12 set -g prefix C-o Updates for tmux in case others want to adapt this.
-
tiadotdev almost 12 yearsIs there a way to set some kind of minimal timeout for prefix+other_key combo in tmux so when pasting code it doesn't trigger any command but when typing backtick+key from keyboard it does because the pause between backtick and the other key was longer?
-
biluochun2010 over 11 yearsBacktick seems like a good idea until you paste in some SQL...
-
tiadotdev over 11 yearsI'm with backtick for about a year and I'll never go back to two-key/combo prefix. Give it a try.
-
tiadotdev about 11 years@Synchro on tmux 1.8 it's not an issue anymore thanks to assume-paste-time option which is on by default (set to 1ms). See here: sourceforge.net/p/tmux/tmux-code/ci/…
-
Elijah Lynn almost 11 years`set -g prefix C-\` was needed for 1.8
-
aymericbeaumet over 10 yearsI've adopted this bind and I find it very convenient. Thanks!
-
Jack O'Connor over 10 yearsMy favorite as well, since I always disable the terminal control flow stuff.
-
Jack O'Connor over 10 yearsCtrl-s is forward search, for when I go to far with Ctrl-r :)
-
aignas about 10 yearsJust to let somebody else know, you should write
'C-\'
instead of ` C-\ ` in the tmux config. -
Mu Qiao about 10 yearsI think Ctrl+O breaks vim
-
nhed about 10 yearsUsed in emacs for
quote-inserted
. Sample use (in emacs): if I want to search for the next tab character -<Ctrl-s>+<Ctrl-q>+<TAB>
-
Susam Pal about 10 yearsI use C-j too. This is what I use in my ~/.tmux.conf:
set -g prefix2 C-j; bind-key C-j send-prefix -2
-
user72923 almost 10 yearsDon't forget to 'tmux source-file /path/to/tmux.conf' when finished to try out the new settings
-
kirelagin almost 10 yearsI found this question looking for alternatives to backtick as it started to cause trouble after I got used to using backticks instead of
$()
in shells. Also it becomes a pain once you start writing a lot of Markdown. I've been using it for several years, but unfortunately I'll have to change it now. -
Matt Roberts over 9 yearsI use this as well. C-Space is quite easy to type.
-
Alex over 9 yearsThe backtick is pretty good. However its not terminal friendly as it turns out. You definitely cannot go wrong with xterm on linux, but terminals like putty and iTerm2 (macos) have issues emulating it properly. Luckily in iTerm2 you can workaround it in the configuration. I don't use windows/putty a lot, so ctrl-space seems to be a feasible workaround. :)
-
Kache about 9 yearsbut then I get in the habit of that command, and when I forget I'm in screen, I start accidentally sending SIGQUITs...
-
OJFord almost 9 yearsWhat if you're writing markdown? How do you escape the prefix?
-
OJFord almost 9 yearsAh, you double-tap it. Nice, might give it a shot.
-
dylnmc over 8 yearswhat about if ever write some bash?
f_len=`cat file | wc -l`
? -
iconoclast over 8 yearsinstead of using
`
in bash, you should try to use the more modern and more readable alternative:$(
and)
-
Mahdi almost 8 yearsI also use C-Space, it is not used almost anywhere else.
-
Arjan almost 8 yearsDefine Mac keyboard ;-)
-
nanitous almost 8 yearsOkay, you've a point here, I meant a Apple Mac US keyboard layout, though regardless a full extended or a macbook keyboard.
-
Steve Jorgensen almost 8 yearsThe only problem I've had with using C-z is that most other people are using C-b, so my muscle memory is off when pair programming on someone else's machine.I end up having to run
fg
a lot after erroneously typing C-z. -
Steve Jorgensen almost 8 yearsThe great think about C-z is that, assuming you don't want to use C-a, it's very close to the left Ctrl key, which is the only control key on most notebook computer keyboards these days. Also close to the Caps Lock if you have that mapped to Ctrl. I map my Caps Lock to Esc since I'm often using a Kinesis Freestyle Solo keyboard that has the Esc key in an awkward place.
-
Dave over 7 yearsCtrl-S is common for stopping console output (aka "freezing" it). This bit me when I tried remapping it.
-
Eric Nguyen over 7 yearsC-space is perfect for me, as I'm on a Chromebook :D
-
Mandrake over 7 years"if it's in a convenient position on your keyboard layout" by default it's not, are you implying that there is some popular remapping that you're using which makes C-\ convenient?
-
Vik about 7 yearsDon't use backticks so often, so I don't mind tapping it twice. This is my fav by far.
-
blockloop almost 7 yearsBased on your recommendation, I have been using C-j for a while and the only conflict I've found is with the CtrlP vim plugin. C-j and C-k are used to move down and up the options, respectively.
-
blockloop almost 7 years
C-j
conflicts with CtrlP. Moving up and down the buffer list usesC-k
andC-j
respectively -
henrebotha almost 6 years@storypixel I think it's more a matter of not assuming what people are using. Nowadays some people (like me) run custom firmware on their keyboards.
-
Olaf Dietsche over 5 yearsOn a German layout keyboard, you would use the caret
^
instead. -
aparkerlue over 5 years
'C-\'
is a terrible prefix key, as building muscle memory around it will cause you to inadvertently sendSIGQUIT
when you're using tmux's that aren't configured this way. If we're going to shadow a process control key combination, thenC-z
is a much more benign option. -
sleighty about 5 yearsI'm trying to do this but if I hold
CAPS-LOCK
(thinking about my next command or something) tmux—or iTerm, not sure what's causing this—receives theESC
command repeatedly causingM-Space
to then not work. Is there a way to disable that repeating key issue? For instance, it works when I quickly pressCAPS-LOCK + Space
, but not if I hold downCAPS-LOCK
for a second or so and then pressSpace
it doesn't register theM-Space
chord... -
doak almost 4 years
Ctrl-Q
is great, hitting it twice to re-enable output is not too bad. -
doak almost 4 yearsThere are a lot more in the Vim-world, like moveing windows around etc. I you are a Vim user, I would avoid remapping your cursor keys.
-
doak almost 4 yearsWhat about
Ctrl-`
? This can be bound (for my setup) byC-@
(found out withcat -v
). -
moopet over 3 years@storypixel on ISO keyboards it's next to A and Z so it's as convenient as the existing screen prefix key / start-of-line, or suspend, both of which I use without issue at the moment and neither of which I wish to shadow.
-
haridsv over 2 yearsThe only issue with using
C-j
for Vim is that it become harder to move to lower window. it is quite handy to useCtrl-W_Ctrl-J
. It is an alias forCtrl-W_j
, but it is so much easier to keepCtrl
key pressed instead of having to release it between thew
andj
keys, especially if you are moving multiple windows (try pressingCtrl-w j Ctrl-w j Ctrl-w j
instead of justwjwjwj
(while keepingCtrl
pressed). -
Robert Smith about 2 yearsErgonomically, this would have been a good option, but Alt + F moves forward a word in Bash
-
Jhon about 2 yearsI use vi mode on bash/zsh, so I never used this.
-
Admin almost 2 years@sleighty you can have
CAPS-LOCK
mapped toESC
when pressed and released andCTRL
when you hold down.C-Space
then works nicely as tmux prefix, but just in general it's also great. -
Admin almost 2 yearsI use
Ctrl+G
to show my file name when I am on vim to make sure that I looking at the correct log file. -
Admin almost 2 years@cviejo, how do you do this mapping based on how long you press?