How to mark a tmux pane and target it from anywhere?
Short answer
tmux select-pane -m # mark the active pane (prefix m)
tmux swap-pane -s '{marked}' # swap the active pane with the marked one
tmux join-pane -s '{marked}' # bring the marked pane into this window
prefix m marks the active pane. The special target {marked} then resolves to that pane from
any window or any session, so moving a pane around no longer starts with looking up indexes:
mark the pane where it lives, navigate to where you want it, and run the swap or the join.
Details
Only one pane is marked at a time. Marking another pane moves the mark, and prefix M
(select-pane -M) clears it. Two format variables expose the state: #{pane_marked} is 1 on
the marked pane, and #{pane_marked_set} is 1 anywhere as long as some pane is marked.
The marked pane is the default source (-s) for join-pane, move-pane, swap-pane and
swap-window. So once a pane is marked you do not even need the token: a bare tmux swap-pane
swaps it with the active pane, and a bare tmux join-pane splits it into the current window.
The mark does not survive the move: on 3.2a, using it with swap-pane or join-pane clears it.
Treat it as one-shot for moves and mark again before the next one.
With no pane marked, {marked} fails with no marked target instead of guessing. That is the
opposite of a bare number, which silently flips between “pane of this window” and “window N”
depending on how many panes you have, so the mark is the safer way to point at a distant pane.
Quote the token in a shell: single quotes around {marked} keep it out of the shell’s hands.
Verified on tmux 3.2a.