How do I reorder tmux windows?
In screen
, I can just type C-a :number 0
to move a window to the top of the window list and push all the other windows down one. What's the equivalent command sequence for tmux
? I looked at the man page, but I'm finding it confusing on this point.
The swap-window
command is closest to what you want.
"Prefix :" (that is Ctrl+B, : by default) brings you to the tmux-command prompt. There you enter:
swap-window -s 3 -t 1
to let window number 3 and window number 1 swap their positions.
To swap the current window with the top window, do:
swap-window -t 0
In the unlikely case of having no window at index 0, do:
move-window -t 0
(if base-index is 0, as it is by default). Command move-window -t <NUMBER>
is by default bound to Ctrl+B, ..
You can bind that command to a key (T for "top" for example) by adding the following to your ~/.tmux.conf
:
bind-key T swap-window -t 0
Adding to Gareth's answer, you can use the following key bindings
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
Pressing Ctrl+Shift+Left (will move the current window to the left. Similarly right. No need to use the modifier (C-b).
For tmux 3.0 version, you should use following key bindings
bind-key -n C-S-Left swap-window -t -1\; select-window -t -1
bind-key -n C-S-Right swap-window -t +1\; select-window -t +1