Mbm329 04:40, March 12, 2012 (UTC)

As of TMUX v1.6, this has been incorporated as a configuration option into the tmux code itself.

renumber-windows [on | off]
       If on, when a window is closed in a session,
       automatically renumber the other windows in numerical
       order.  This respects the base-index option if it has
       been set.  If off, do not renumber the windows.

Occassionally your windows will become larger than 9 and when you remove some windows in the middle like windows 2 or 5 or the like, you might want to re-number them. Here's a small script I call "tmux_renum". By running it from any window in any session, it will renumber all the windows in all sessions from 0.

for session in $(tmux ls | awk -F: '{print $1}') ;do
  active_window=$(tmux lsw -t ${session} | awk -F: '/\(active\)$/ {print $1}')
  for window in $(tmux lsw -t ${session} | awk -F: '{print $1}') ;do
    if [ ${window} -gt ${inum} ] ;then
      echo "${session}:${window} -> ${session}:${inum}"
      tmux movew -d -s ${session}:${window} -t ${session}:${inum}
    if [ ${window} = ${active_window} ] ;then
  tmux select-window -t ${session}:${new_active_window}

You can even setup a keybinding for it in your tmux config. In the ~/.tmux.conf, I removed the "r" keybinding and replaced it with:

# r = tmux renumbering script
unbind r
bind r run "~/bin/tmux_renum"

Thanks to Gerald Young for inspiration.

Community content is available under CC-BY-SA unless otherwise noted.