tmux – Renumbering Windows in Tmux

tmux

I frequently end up with more than ten windows in tmux. Later on, I close some of my older ones. Is there a way to renumber, say window 15, to window 3 (which doesn't exist anymore)? Or to pack them all up again, so that there are no empty slots? I'd like to do this because it is difficult to jump to higher numbered windows, because you can't do Ctrl+B, 15. I have to use Ctrl+B, w to list the windows and then type the letter corresponding to the window I want to open.

I know that I can swap windows. For example, I could create a new window (Ctrl+B, c) which would open in the empty slot 3. I can then swapw window 15 and window 3 and then close window 15. Obviously, this is a tedious approach.

How do you manage many windows in tmux?

Best Answer

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.

Related Question