Move and renumber windows
The window list reads 0:editor 1:logs 2:tests 3:shell.
An index is a slot in the window list. These three commands change slots without closing anything:
C-b .- prompt for a new index for the current window
swap-windowatC-b :- trade the current window with the one holding the marked pane
movew -ratC-b :- renumber every window from 0, closing the gaps
The mark is the same one from C-b m: mark a pane in the window you want to move, go to the window you want it to trade with, then run swap-window.
Press C-b 3 to reach tests, then C-b ., type 2, Enter.
The list shows 2:tests.
Press C-b 1 to reach editor, then C-b m.
Its pane is marked.
Press C-b 0 to reach logs, then C-b :, type swap-window, Enter.
editor is now at 0 and logs at 1.
Press C-b :, type movew -r, Enter.
7:shell becomes 3:shell, leaving 0:editor 1:logs 2:tests 3:shell.
Replacing an occupied index
move-window refuses an index that is already taken, unless you add -k to replace whatever is there.
Here is what just happened.
C-b . runs move-window with the index you typed. swap-window found the marked pane’s window, editor, and exchanged it with the current one; the mark stays set afterwards. move-window -r walked the list and reassigned indexes in order.
- Prompt for a new index for the current windowC-bthen.
- Swap the window containing the marked pane with the current window:swap-window
- Renumber windows to remove gaps in the window list:movew -r
Go further
move-window -s other:1 -t 5moves a window between sessions.swap-window -s 0 -t 3swaps by index without a mark;-dkeeps you on the window you ran it from.- The
renumber-windowsoption makes tmux renumber automatically whenever a window closes.
- 1
swap-windowswaps the window holding the marked pane with the current window. Mark ineditor, then switch tologsbefore running it. - 2
C-b .prompts for a new index for the current window.movew -rrenumbers to close gaps. - 3On
tests:C-b .2Enter. Oneditor:C-b m. Onlogs:C-b :swap-window. ThenC-b :movew -r.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- The tests window has been moved to index 2— not done yet
- The window list reads 0:editor 1:logs 2:tests 3:shell with no gaps— not done yet