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.
Related: How to split a pane horizontally in tmux
Related: How to split a pane vertically in tmux
Related: How to resize panes in tmux
Need another pane first: How to split a pane horizontally in tmux or How to split a pane vertically in tmux.
$ 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.
$ 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.
$ 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.
swap-pane -s 0 -t 2
$ tmux swap-pane -d -s demo:0.0 -t demo:0.2