How to close all panes but the current pane in tmux

keyboard shortcutstmux

I have a key bound to setup panes to my liking, but sometimes things get messed up or out of hand and I want to close all the panes and rerun the script. Is there a simple tmux command to close all panes except the one I am currently in?

Best Answer

You can use the "kill-pane" command.

 kill-pane [-a] [-t target-pane]
               (alias: killp)
         Destroy the given pane.  If no panes remain in the containing window, it is also destroyed.  The -a option kills all but the pane given with -t.

So, for example if you want to kill all the panes except for pane 0:

kill-pane -a -t 0

If you don't know what you pane numbers are you can use the "display-panes" command:

 display-panes [-t target-client]
               (alias: displayp)
         Display a visible indicator of each pane shown by target-client.  See the display-panes-time, display-panes-colour, and display-panes-active-colour
         session options.  While the indicator is on screen, a pane may be selected with the '0' to '9' keys.