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
tmux swap-window [-d] [-s src-window] [-t dst-window]Options
| Flag | Description |
|---|---|
| -d | Don't make the swapped window the current window |
| -s src-window | Source window (defaults to the marked pane's window, if one is marked) |
| -t dst-window | Destination window |
Examples
Swap window 2 with window 1
tmux swap-window -s 2 -t 1Swap current window with window 0, stay put
tmux swapw -d -t 0Swap the current window with the window to its left.
tmux swap-window -t :-1Swap window 2 of the api session with window 0 of the ops session.
tmux swap-window -s api:2 -t ops:0Default 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