Search code examples
command-linetmuxcommand-line-tool

How can I shift all window numbers down by the appropriate number to “collapse” the window numbers?


I am (manually) moving this question to SO from superuser because I observed there is a tmux tag here, and I believe it is a sufficiently unusual question that the power users of tmux on SO might better be able to address it.

Suppose I have 5 windows, and I decide to delete window 1.

Is it possible to shift all the window numbers down by 1 with a single command, so that 2 becomes 1, 3 becomes 2, 4 becomes 3, and 0 stays where it is?

The above is merely an example. I am wondering if it can be done for an arbitrary number of windows, and an arbitrary number of "missing" windows.

I have looked at this question and it certainly makes things easier, but it does not address the current question.


Solution

  • Starting in tmux 1.7, the move-window command knows the -r option that tells it to renumber windows in the desired manner. For example—after closing your window at index 1—you could run tmux move-window -r (from a shell) or type Prefix + :move-window -r (in an attached client).

    If you always want windows to be automatically renamed, then you can set the renumber-windows session option. If you want this for all your sessions, then you might want to set it globally in your .tmux.conf:

    set-option -g renumber-windows on