Todd Freed is right, the "correct" way to do this is using \;
. Sort of. But there's a snag.
You see, you join a sequence of tmux commands together by giving tmux the conjunction ;
. Thus, in a file sourced by tmux, you might say
new-session "monitor1" ; split-window -v "monitor2"
if, for some reason, you wanted that all on one line. Now, you can give that one-line compound statement to the tmux
command from a shell also but the ;
must be escaped so that the shell interprets it as another argument for tmux
. Thus the equivalent of the above from the shell is
$ tmux new-session "monitor1" \; split-window -v "monitor2"
Similarly, the tmux bind-key
command takes a series of arguments which are the tmux command and arguments to run when the key is pressed. If you wanted to bind C-q
to the above sequence from inside a file sourced by tmux, you'd say
bind-key -n C-q new-session "monitor1" \; split-window -v "monitor2"
Here we've escaped the ;
from tmux, so that tmux doesn't interpret it as the end of the bind-key
command, but as another argument to bind-key
telling it to form a compound command as the bound value of the C-q
key.
So what happens when we want to make tmux do that from the shell? A whole lot of escaping.
$ tmux bind-key -n C-q new-session "monitor1" \\\; split-window -v "monitor2"
First, we have to escape the \
and the ;
each from the shell, causing the shell to pass the two characters \;
as an argument to tmux
. This then escapes the ;
from tmux, causing it to assign the entire compound statement as the binding of C-q
.
Now, all that said, if you use a complex tmux setup like this repeatedly, I'd suggest that you create a tmux file to keep it in:
# In split-windows.tmux:
new-session "monitor1"
split-window -v "monitor2"
bind-key -n C-s new-window "monitor4"
# ...etc...
And then:
$ tmux source split-windows.tmux # (or even make an alias for this)
It'll be a lot easier to maintain that way.
Best Answer
You want to invoke a sequence of keystrokes (first
Ctrl-b
, then n ranging from 0 to 9).Your best bet is to use a keyboard shortcut utility such as Butler or Keyboard Maestro to do this for you.
Using Butler:
Select + » Smart Item » Keystrokes, configure the hotkey
Cmd-1
. PressCtrl-B
, then1
for the Keystrokes. Configure it to be only valid in Terminal (or iTerm). It will warn you that other applications might not like it, but you know that already.Using Keyboard Maestro:
Create a new group on the left that is only available in Terminal (or iTerm).
Add a new item, triggered by Hot Key Trigger (
Cmd-1
) and add two Keystrokes to its actions:Ctrl-B
and1
.You might also want to take a look at this topic -- doesn't use
Command
though, and didn't work for me using Terminal.From the tmux documentation:
They don't support a third modifier key.