Swapping panes in tmux moves two existing pane positions within the current window without killing the programs already running inside them. It is the quickest way to fix a layout when the right commands are open but the panes ended up in the wrong places.

The exact swap-pane command works against pane targets in the current window, so the practical job is to identify the two pane numbers you want to exchange and then run one direct swap. Current tmux releases still include the default C-b { and C-b } bindings for adjacent swaps, but the command form is the clearest way to swap any two panes on purpose.

The steps below assume you are already inside the tmux window that contains the panes you want to rearrange. If the layout changed since you last looked at it, confirm the current pane numbers first because pane numbers are assigned per window and the wrong targets will swap the wrong panes.

Steps to swap panes in tmux:

  1. Confirm the current window already contains at least two panes before you try to swap anything.
  2. List the panes in the current window so you can identify the source and destination pane numbers before swapping them.
    $ tmux list-panes -t demo:0 -F '#{pane_id}: index=#{pane_index} left=#{pane_left} top=#{pane_top} active=#{pane_active}'
    %0: index=0 left=0 top=0 active=0
    %2: index=1 left=0 top=13 active=1
    %1: index=2 left=41 top=0 active=0

    In this example pane 0 is at the upper left, pane 1 is below it, and pane 2 is on the right.

  3. Run swap-pane with the two pane targets you want to exchange.
    $ tmux swap-pane -s demo:0.0 -t demo:0.2

    The -s flag selects the source pane and -t selects the destination pane, using the format session:window.pane.

  4. List the panes again to confirm the two pane IDs moved to each other's positions.
    $ tmux list-panes -t demo:0 -F '#{pane_id}: index=#{pane_index} left=#{pane_left} top=#{pane_top} active=#{pane_active}'
    %1: index=0 left=0 top=0 active=1
    %2: index=1 left=0 top=13 active=0
    %0: index=2 left=41 top=0 active=0

    The %1 pane moved from index 2 to index 0 and the %0 pane moved to index 2, which confirms the swap completed.

Notes

  • Inside the tmux command prompt opened with C-b :, the same current-window swap can be run as this shorter form.
    swap-pane -s 0 -t 2
  • The default prefix is Ctrl-b, and current tmux releases still bind C-b { to swap-pane -U and C-b } to swap-pane -D for swapping the active pane with the previous or next pane number.
  • Use swap-pane -d when you want tmux to keep the current active pane instead of moving focus during the swap.
    $ tmux swap-pane -d -s demo:0.0 -t demo:0.2