A tmux window divides the screen into panes. The swap-pane command exchanges two pane positions while keeping their running programs intact; selecting another pane only changes keyboard focus.
The swap-pane command targets panes by the numbers tmux shows for a window. It also accepts pane IDs such as %0 or a full session:window.pane target, but the numbers are enough for two panes in the current window.
The same swap works for panes stacked vertically or placed side by side. Each program takes over the other pane's screen area, including its dimensions, without requiring a new split or a different layout.
To switch keyboard focus without moving panes: How to select a pane in tmux.
To change pane dimensions: How to resize panes in tmux.
Related: How to split a pane horizontally in tmux
Related: How to split a pane vertically in tmux
Related: How to use the tmux command prompt
Steps to swap pane positions in tmux:
- Show the pane numbers in the current window.
C-b q
The numbers stay on screen for about a second. Use the configured prefix instead of C-b if it has changed.
Related: How to change tmux prefix key to Ctrl-a
Need another pane first: How to split a pane horizontally in tmux or How to split a pane vertically in tmux. - Run swap-pane with the two pane numbers at the C-b : command prompt.
swap-pane -s 0 -t 2
The 0 and 2 here stand for the two numbers from your own window. At a shell prompt in the same window, the same swap is tmux swap-pane -s 0 -t 2. Keyboard focus ends on the pane now in the -s position. To stay with the pane you are moving, put its number after -s and add -d, as in swap-pane -d -s 0 -t 2.
To trade the active pane with a neighboring one instead, press C-b { for the previous pane or C-b } for the next pane.
- Check that the two programs have changed places in the window.
Both programs keep running, and any other pane stays where it was. Pane numbers follow screen position, so C-b q shows the same numbers as before.