How to swap panes in tmux?

Quick Answer

To swap or exchange panes in tmux, press Ctrl+b followed by { to move the current pane left/up or } to move it right/down. For more control, use the swap-pane command.

Ctrl+b+{or}

Detailed Explanation

Swapping panes allows you to rearrange your tmux workspace without closing and recreating panes. This is useful for organizing related tasks or prioritizing your workflow by moving important panes to more prominent positions.

Using keyboard shortcuts:

  • Ctrl+b { - Move the current pane left (or up if arrangement doesn't allow left)
  • Ctrl+b } - Move the current pane right (or down if arrangement doesn't allow right)

Using tmux commands for precise control:

  • Ctrl+b : then type swap-pane -s 2 -t 3 - Swap pane 2 with pane 3
  • Ctrl+b : then type swap-pane -U - Swap with previous pane (up in the layout)
  • Ctrl+b : then type swap-pane -D - Swap with next pane (down in the layout)

Finding pane numbers:

To see pane numbers (needed for the swap-pane command):

  • Ctrl+b q - Display pane numbers briefly

Rearranging Layouts

Instead of swapping individual panes, you can also cycle through different layout arrangements:

  • Ctrl+b Space - Cycle through available layouts
  • Ctrl+b Alt+1 - Even horizontal layout
  • Ctrl+b Alt+2 - Even vertical layout
  • Ctrl+b Alt+3 - Main horizontal layout
  • Ctrl+b Alt+4 - Main vertical layout
  • Ctrl+b Alt+5 - Tiled layout