How to move a pane from one tmux window to another?

By Romain Dorgueil

Short answer

tmux join-pane -h -s 3.1       # pane 1 of window 3 -> split to the RIGHT of the active pane
tmux join-pane -v -s build.0   # stacked below instead; add -b to insert before (left / above)

join-pane moves one pane into the current window as a new split. -s is the source pane, -t the destination (default: the active pane). -h puts them side by side, -v stacks them, -b inserts before instead of after.

Details

Nothing restarts: join-pane re-parents the pane, so whatever runs inside keeps its pid across the move. Moving a pane is safe even mid-build.

Qualify the source. A bare -s 3 is ambiguous: it means pane 3 of the current window when that pane exists, and window 3 otherwise, silently. Use a window.pane form (3.1), a pane id (%7), a window name (build.0), or mark the pane first (prefix m) and join with -s '{marked}'.

A window that loses its last pane closes itself, so draining a window with joins needs no cleanup. To pull in every pane of a window at once, loop over them and fix the layout at the end:

src=3
for p in $(tmux list-panes -t "$src" -F '#{pane_id}'); do
  tmux join-pane -h -s "$p"    # into the current window
done
tmux select-layout tiled       # clean up the layout afterwards

The exact opposite is break-pane, bound to prefix ! by default: it takes the active pane out of its window and gives it a fresh window of its own.

Verified on tmux 3.2a.

Related