3

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.

Community
  • 1
  • 1
merlin2011
  • 71,677
  • 44
  • 195
  • 329

2 Answers2

4

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
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
0

User gospes provided a solution that I believe does exactly what you want. It seems to work perfectly on my end and it's a simple addition to .tmux.conf:

bind R                                      \
    set -g renumber-windows on\;            \
    new-window\; kill-window\;              \
    set -g renumber-windows off\;           \
    display-message "Windows reordered..."

The command set -g renumber-windows on by itself works fine, of course, but can be a little jarring if you're not ready for an immediate renumbering.

Community
  • 1
  • 1
nklauza
  • 1,501
  • 1
  • 12
  • 12