Hello, folks! As someone who has been in the trenches with Tmux, I understand the need to control multiple panes effectively. Sometimes you want to execute the same command across all panes simultaneously, rather than tediously typing it in each pane. Well, in this blog post, I will show you exactly how to do that – how to send commands to all panes in Tmux. So, let’s not waste any more time and dive straight in!
If you’re taking your first steps with Tmux, the basics of Tmux is a great starting point. For the Tmux veterans, let’s get this show on the road!
Let’s consider a case where you have to send a command to all the panes in a window, for example – an ssh command to connect to a remote host, across all panes or another example is to clear history in all your panes).
Using prefix synchronize-panes command
You can use <prefix> :setw synchronize-panes on
to set the ability to send commands to all panes. All panes in the given window are all now synchronized to receive the same command.
Here, let’s assume that your <prefix>
is Ctrl-B
, which is the default prefix.
Let’s take an example, let’s say you want to clear history across all panes in a window. You can do the follow set of commands-
Ctrl-B
:
setw synchronize-panes on
clear-history
To disable the synchronize-panes state, you can use the following command-
Ctrl-B
:
setw synchronize-panes off
Using on
or off
is optional. The command can also be used to toggle between the on
and off
states. So, the below command can be used to toggle states-
Ctrl-B
:
setw synchronize-panes
Shortcut Ctrl-B, then, Ctrl-S
The default shortcut to synchronize panes is-
Ctrl-B
Ctrl-S
Custom Shortcut in ~/.tmux.conf
You can create a custom shortcut if Ctrl-S
is confusing. You can unbind the Ctrl-S
and add a new binding to another keypair, like Ctrl-Y
.
You can create a custom shortcut in your ~/.tmux.conf
–
unbind C-S
bind C-Y set-window-option synchronize-panes
You have to reload changes in tmux config tmux.conf
so that it reflects-
tmux source-file ~/.tmux.conf
So, the new shortcut to synchronize panes is-
Ctrl-B
Ctrl-Y
I hope you found this article useful, glad that you found it easy to send commands to all panes in a window in Tmux. And that’s a wrap! We’ve now uncovered the simple process of sending commands to all panes in Tmux. It’s a nifty trick, one that will save you a ton of time when working with multiple panes. But remember, with great power comes great responsibility. Ensure you’re executing the right command before blasting it across all panes. Keep playing around with Tmux, and stay tuned for more useful tips and tricks!
You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.