Table of Contents

How to move a window in tmux

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.

Steps to move a window in tmux:

  1. 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.

  2. 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.

  3. 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.

  4. 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