How to synchronize panes in tmux?

Quick Answer

Synchronize panes in tmux by toggling synchronize-panes with Ctrl+b :setw synchronize-panes on to send the same commands to all panes in a window simultaneously. Turn it off with Ctrl+b :setw synchronize-panes off.

Ctrl+b :setw synchronize-panes on

Detailed Explanation

Synchronize-panes is a powerful tmux feature that allows you to send the same keyboard input to multiple panes simultaneously. This is incredibly useful when you need to run identical commands across multiple servers, environments, or directories.

Enabling synchronize-panes:

To turn on synchronize-panes:

  1. Press Ctrl+b (tmux prefix)
  2. Press : to enter command mode
  3. Type setw synchronize-panes on and press Enter

Disabling synchronize-panes:

To turn off synchronize-panes:

  1. Press Ctrl+b
  2. Press : to enter command mode
  3. Type setw synchronize-panes off and press Enter

Visual indicator:

It's helpful to have a visual indicator when synchronize-panes is active. Add this to your ~/.tmux.conf to change the status line color when synchronize-panes is on:

set-option -ag status-right '#{?pane_synchronized, #[bg=red]SYNC#[default],}'

Adding a key binding:

To toggle synchronize-panes with a single key combination, add this line to your ~/.tmux.conf:

bind e set-window-option synchronize-panes

With this binding, you can toggle synchronize-panes by pressing Ctrl+b followed by e.

Pro Tip

When using synchronize-panes with multiple servers, consider setting a different prompt color in each pane before enabling synchronization. This helps you visually distinguish between different environments while typing the same commands.

Use Cases

Synchronize-panes is especially useful for:

  • Running updates on multiple servers simultaneously
  • Teaching or demonstrating commands to a group
  • Comparing outputs across different environments
  • Running the same test or diagnostic across multiple systems