Skip to main content
Browse referenceAll guides
Back to Commands
Window ManagementPrefix + < then l or r

swap-window

Short form: swapw

Swap two windows so they exchange positions. With -d the active window is not changed to follow the move.

How swap-window works

swap-window makes two windows trade places, so each takes the other's index. It is how you reorder windows in the status line. The windows can even be in different sessions.

Name the windows with -s and -t. If you leave out -s, tmux uses the current window, or the window of the marked pane if you marked one with Prefix + m. With -d, the swapped window does not become the current window.

The default window menu (Prefix + <) has Swap Left and Swap Right entries that call swap-window for you. For moving one window to an empty index instead, use move-window.

Synopsis

bash
tmux swap-window [-d] [-s src-window] [-t dst-window]

Options

FlagDescription
-dDon't make the swapped window the current window
-s src-windowSource window (defaults to the marked pane's window, if one is marked)
-t dst-windowDestination window

Examples

Swap window 2 with window 1

bash
tmux swap-window -s 2 -t 1

Swap current window with window 0, stay put

bash
tmux swapw -d -t 0

Swap the current window with the window to its left.

bash
tmux swap-window -t :-1

Swap window 2 of the api session with window 0 of the ops session.

bash
tmux swap-window -s api:2 -t ops:0

Default Keybinding

Prefix + < then l or r (window menu: Swap Left / Swap Right)

Default prefix is Ctrl+b

Common Mistakes

  • It fails if there is no window at the source index. Check with tmux lsw first.
  • Names, panes, and programs travel with each window; only the index numbers trade places. If you expected the names to stay put, you wanted rename-window.
  • Across sessions, each session ends up with the other's window. To give a window to another session without taking one back, use move-window.

Pro Tips

  • •Combine with -d to reorder windows without following the move
  • •Use move-window to renumber rather than swap