18

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?

29

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).

  • thanks for this option, that's exactly what I was looking for. tmux is amazing – Tropilio Sep 18 at 14:18
3

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

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

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

  • That worked, thanks. I had a zero window actually, so I needed to start with i=0. – mahemoff Sep 28 '12 at 15:36
  • 2
    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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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