How do I make tmux reorder windows when one is deleted?

Jimmy Zelinskie picture Jimmy Zelinskie · Dec 12, 2011 · Viewed 8.7k times · Source

I have three windows:

1:zsh 2:vim* 3:htop

When I delete the current window (#2), I have these windows left:

1:zsh 3:htop

How can I make it so that it automatically renumbers them as

1:zsh 2:htop

If I recall correctly, this is the default behavior of GNU Screen. I know I could always :swap-window, but I would like to know if this is possible automatically.

Answer

purucat picture purucat · Sep 23, 2013

Let's do it more simply.

If you are using tmux below version 1.7, append next line to ~/.tmux.conf:

 bind-key C-s run "for i in $(tmux lsw|awk -F: '{print $1}'); do tmux movew -s \$i; done"

You could sort all windows, by typing PREFIX-KEY, then Ctrl + s.

Else, if you are using tmux version 1.7 or above, as already everybody says, append next line to ~/.tmux.conf:

 set-option -g renumber-windows on