Renumbering windows in tmux
Looks like you need this:
move-window [-rdk] [-s src-window] [-t dst-window] (alias: movew) This is similar to link-window, except the window at src-window is moved to dst-window. With -r, all windows in the session are renumbered in sequential order, respecting the base-index option.
Calling movew
without parameters moves current window to first free position. movew -r
will renumber all the windows at once.
tmux 1.7 has a couple of features that can help establish and maintain gapless/packed window numbers:
The
move-window
command learned a new-r
option that will renumber all the windows in a session (either the current session, or one specified with the-t
option).If you have a set of windows like { 1:A, 4:B, 15:C }, then you can run
move-window -r
to renumber them to { 1:A, 2:B, 3:C } (they will start with yourbase-index
; 1 in this example).When the
renumber-windows
session option is enabled, tmux will automatically renumber the windows of a session (as withmove-window -r
) after any window is closed.If you like this behavior, you can turn it on in the global value so that all sessions that to not override it will automatically have it enabled:
set-option -g renumber-windows on
I often find myself in a situation where I have gaps in between window numbers, for example a session with windows:
1 3 4 8 9 13
I wrote a tmux script to reorder them without changing their respective order nor activating the 'renumbering-windows' option. The result:
1 2 3 4 5 6
Put the following in your .tmux.conf:
bind R \
set -g renumber-windows on\; \
new-window\; kill-window\; \
set -g renumber-windows off\; \
display-message "Windows reordered..."
Hit [PREFIX]-R to reorder windows (or change the binding).
I'm currently running tmux 1.9a.
The above can be replaced with the much simpler:
bind R \
move-window -r\; \
display-message "Windows reordered..."