Moving a tmux window changes its position in the current session's window list without restarting the shell, editor, or long-running command inside it. Reordering windows keeps the status bar aligned with the way the session is actually being used, which makes prefix-number navigation faster and reduces wrong-window jumps.
The move-window command retargets an existing window to a different window index inside the same session. Current tmux releases still keep the default Ctrl-b . binding for moving the current window from the command prompt, but the direct command form is the clearest way to move a specific window, insert it before or after another one, or replace an occupied slot on purpose.
Window numbers belong to each session and often start at 0 unless base-index has been changed in the configuration. List the current windows before moving anything, because tmux refuses an occupied destination index unless -a, -b, or -k is used, and moving a window to an unused slot can leave a numbering gap until you renumber the session.
Related: How to create a window in tmux
Related: How to rename a window in tmux
Related: How to customize the tmux status bar
Steps to move a window in tmux:
- List the windows in the target session so the current window numbers and names are visible before you move anything.
$ tmux list-windows -t demo 0: shell (1 panes) [80x24] [layout b25d,80x24,0,0,0] @0 1: logs- (1 panes) [80x24] [layout b25e,80x24,0,0,1] @1 2: editor* (1 panes) [80x24] [layout b25f,80x24,0,0,2] @2 (active)
The number before each colon is the window index used in the session:window target syntax for move-window.
- Move the source window to an unused index when the destination slot is already known.
$ tmux move-window -s demo:2 -t demo:3
-s selects the source window and -t selects the destination index, so demo:2 becomes window 3 in the demo session.
If the destination already exists, tmux stops with an error such as index in use: 1 instead of shifting windows automatically.
- List the windows again to confirm the window now appears at the new index.
$ tmux list-windows -t demo 0: shell (1 panes) [80x24] [layout b25d,80x24,0,0,0] @0 1: logs- (1 panes) [80x24] [layout b25e,80x24,0,0,1] @1 3: editor* (1 panes) [80x24] [layout b25f,80x24,0,0,2] @2 (active)
The asterisk marks the current window, and the numbering gap shows that the move succeeded even though index 2 is now unused.
- Renumber the session after the move when the window list should become compact again without unused gaps.
$ tmux move-window -r -t demo
This renumbers the session sequentially, so the same editor window returns from index 3 to index 2 in the example above.
Notes
- Inside an attached tmux client, the default Ctrl-b . binding opens a prompt for the new window index and runs move-window against the current window.
- Use move-window -a -s demo:2 -t demo:0 to insert the source window after an existing target window, or move-window -b -s demo:2 -t demo:1 to insert it before one.
- Use move-window -k -s demo:2 -t demo:1 only when the window currently occupying the destination index can be destroyed deliberately, because -k removes that existing window to make room.
- If base-index is set to 1 in /.tmux.conf or the system tmux configuration, the same commands still work but the first window number in the session starts at 1 instead of 0.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
