Reorder tmux windows

tmux

How can I efficiently reorder windows in tmux? For example, having this set of windows:

0:zsh  1:elinks  2:mutt  3:irssi  4:emacs  5:rss  6:htop

What would I have to do to move rss to between elinks and mutt, ending up with:

0:zsh  1:elinks  2:rss  3:mutt  4:irssi  5:emacs  6:htop

I know how to use move-window to move a window to a yet-unused index, and I could use a series of them to achieve this—but, obviously, this is very tedious.

Best Answer

swap-window can help you:

swap-window -t -1

It moves current window to the left by one position.

From man tmux:

swap-window [-d] [-s src-window] [-t dst-window]
             (alias: swapw)
This is similar to link-window, except the source and destination windows are swapped. 
It is an error if no window exists at src-window.

You can bind it to a key:

bind-key -n S-Left swap-window -t -1
bind-key -n S-Right swap-window -t +1

Then you can use Shift+Left and Shift+Right to change current window position.

Related Question