Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

tmux

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.

like image 843
Jimmy Zelinskie Avatar asked Dec 12 '11 03:12

Jimmy Zelinskie


People also ask

How do I renumber windows in tmux?

The recently released tmux 1.7 includes the renumber-windows session option (keeps window numbers gapless), and the move-window -r command (does a one-time renumbering of windows). If you want “gapless” numbers for all sessions, then you could put set -g renumber-windows on in your config file (once you have tmux 1.7).

How do you delete a window in tmux?

ctrl + d kills a window in linux terminal, also works in tmux.


2 Answers

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 
like image 143
purucat Avatar answered Sep 24 '22 08:09

purucat


Since tmux 1.7, you can type just one command to do so:

tmux movew -r 
like image 44
northteam Avatar answered Sep 22 '22 08:09

northteam