How to move windows in tmux?

Quick Answer

To move a window to a different position in tmux, use move-window or swap-window. The shorthand command is :movew followed by the destination index.

Ctrl+b :movew -t 2

Detailed Explanation

Windows in tmux are like tabs in a traditional terminal, and sometimes you may want to reorder them for better organization. tmux provides several commands to move and reposition windows.

Move window using tmux command mode:

Press Ctrl+b followed by : to enter command mode, then:

movew -t N

Where N is the destination index. This moves the current window to position N.

Move a specific window to a new position:

To move window at position 3 to position 1:

movew -s 3 -t 1

Swap windows:

To swap the current window with window 0:

swap-window -t 0

To swap window 2 with window 4:

swap-window -s 2 -t 4

Keyboard shortcuts for moving windows:

tmux doesn't have default keyboard shortcuts specifically for moving windows, but you can add these to your .tmux.conf:

# Move window left
bind-key -n C-S-Left swap-window -t -1
# Move window right
bind-key -n C-S-Right swap-window -t +1

Pro Tip

To avoid "Window X doesn't exist" errors when moving windows to edges, add the -r flag to enable wraparound: swap-window -r -t -1