To renumber windows in tmux, use the move-window
command with the -r
flag to automatically renumber all windows sequentially. Run Ctrl+b : move-window -r
to close gaps in window numbering. For automatic renumbering whenever windows are created or closed, add set -g renumber-windows on
to your ~/.tmux.conf
file.
# One-time renumbering Ctrl+b :move-window -r # Automatic renumbering (in ~/.tmux.conf) set -g renumber-windows on
Window numbering in tmux starts at index 0 (or 1 if configured) and increments for each new window. When you close windows, gaps can appear in the numbering sequence. Renumbering windows keeps your window indexes sequential, making navigation more intuitive.
To renumber all windows on demand:
move-window -r
and press EnterThis command will renumber all windows sequentially, closing any gaps in the numbering.
To enable automatic window renumbering (available in tmux 1.7 and later):
# Add to your ~/.tmux.conf set -g renumber-windows on
With this option enabled, tmux will automatically renumber windows whenever a window is closed, ensuring that window numbers remain sequential at all times.
You can also manually move windows to specific numbers:
# Move current window to position 3 Ctrl+b :move-window -t 3 # Swap window 2 with window 4 Ctrl+b :swap-window -s 2 -t 4 # Move window 2 to position 4, shifting other windows if needed Ctrl+b :move-window -s 2 -t 4
The -s
flag specifies the source window, and -t
specifies the target position. If you omit -s
, the current window is used as the source.
By default, tmux starts window numbering at 0. Many users prefer to start at 1 for easier keyboard navigation (since the 1 key is more accessible than 0). To change this:
# Add to your ~/.tmux.conf set -g base-index 1 setw -g pane-base-index 1
The first line sets window numbering to start at 1, and the second line does the same for panes within windows.
To create a custom keybinding for renumbering windows:
# Add to your ~/.tmux.conf bind R move-window -r \; display-message "Windows renumbered"
With this configuration, pressing Ctrl+b R will renumber your windows and display a confirmation message.
With properly numbered windows, you can use these navigation shortcuts: