Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using tmux, I closed a window indexed 3, so now I have 1,2,4, ...

I'd rather have windows sequential, so is there any way to force them to re-index?

share|improve this question
up vote 19 down vote accepted

tmux 1.7 includes the renumber-windows session option that maintains a “gapless” sequence for a session’s window numbers. You can set the option “globally” to have it apply to all sessions that have not overridden the global value. E.g. in your ~/.tmux.conf:

set-option -g renumber-windows on

If you do not always want all your sessions to have “gapless” window numbers, then you can use move-window -r (the option is also new to *tmux 1.7) to renumber the windows in just the current session (or some other session if you use the -t option).

share|improve this answer

There's no builtin way to do it, but this bash script should work. Run it from within the session:

tmux list-windows | cut -d: -f1 | while read winindex; do 
  if (( winindex != i )); then
    tmux move-window -d -s $winindex -t $i
  (( i++ ))

The -d flag to move-window avoids giving that window focus.

share|improve this answer
That worked, thanks. I had a zero window actually, so I needed to start with i=0. – mahemoff Sep 28 '12 at 15:36
Ah I forgot I had set-option -g base-index 1 in .tmux.conf. – Thor Sep 28 '12 at 15:56
Even with the tmux 1.7 new features, I found this implementation useful to avoid moving some windows. – dequis Aug 19 '13 at 4:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.