Synchronize panes in tmux

So, you want to run the same command over different terminals? By the end of this blog, hopefully you will know about this neat trick/hack to solve the problems.

Hopefully, you’re familiar with tmux. If not, basically it is a tool that is used as terminal multiplexer. You can create, access, control multiple terminals from a single screen(and many more things).

So, we will be using it to run the same command in different terminals. The command to do this [prefix]:setw synchronize-panes. The default prefix is `Ctrl + B``.

To disable this you can re-run the above command([prefix]:setw synchronize-panes)to toggle the functionality.

pane synchronization in tmux

 

Let us go through the above demonstration step by step:

  • Create a new session
    tmux new -t random
    
  • Split the window into multiple panes.
    • For vertical splitting you can use the shortcut [prefix] %, for vertical use [prefix] "
  • Synchronize Panes
    • Use the command prefix :setw synchronize-panes to run the same command on all panes.
  • Disable the functionality
    prefix :setw synchronize-panes
    

Some other situations where you may find this useful:

  • When debugging the same code for a different version of a python(or any other language). Suppose your code works when well in python3.6 but somehow fails in python3.7.
  • You want to make the same change in inside your different projects.

Hopefully you can now execute the same command in different panes to reduce your time. That's it in this post. Till we meet in another post, keep hacking!!!

0 Comments

Login to join the discussion