77

Short of doing this, is it possible to move a running command in a pane to another tmux session?

1
  • For people landing from Google: in recent TMUX versions, there's a much more easy way than the accepted answer (which is 7 years old). See the answer by @MacMartin.
    – Neinstein
    Commented Dec 16, 2022 at 10:25

4 Answers 4

31

Tmux has the shortcut: <prefix>. (a dot)

<prefix>. then input 6<enter> - move current window to position 6 (in the current session) <prefix>. then input 2:6<enter> - move current window to position 6 in session 2 (see als session names/numbers with <prefix>s or <prefix>:-ls<enter>

(also new for me: <prefix>! to move a pane (from a split) to a new window)

tested for Version: 2.3 on Debian9/Manjaro and 1.8 on RHEL 7 (thx @HEGX64)

2
  • 5
    I messed around with this for a bit and discovered that you don't need to specify the destination window position. That is to say: <prefix>.0:<enter> moves the current window into session 0 at the next available position. Very handy.
    – Jon Carter
    Commented Oct 1, 2020 at 0:39
  • This also works for me on tmux version 1.8 on RHEL 7. I doubt many people are using older versions that that so you can probably remove first sentence if you want to.
    – HEGX64
    Commented Feb 6, 2023 at 3:30
103

Yes it's pretty easy, use the move-pane tmux command. For more info run

man tmux | less -I '+/move-pane'

The tricky part is just knowing how tmux references sessions, windows and panes in the commands to manipulate panes etc.

Step one

Move into the pane you want to move to the other session

Step two

Get the name of the target session by running <prefix>s.

On my system that produces:

 (0) + 0: 8 windows (attached)  
 (1) + 1: 1 windows 
       ^
       |
    This is the session name. It could be different 
    on your system and it could be a word (not just a number).

Step 3 - run command

<prefix>:move-pane -t <session_name>:<window number>
                      ^^^^^^^^^^^^^^ the name from above goes in here

So on my system I moved into the pane with the running process, ran

<prefix>:move-pane -t 1:1

and the pane with the process in it moved to window one on the session 1.

It gets inserted as a split, so usually you would want to run window on the other session as a throwaway window.

Note: it seems that the target window does need to exist, else the move-pane command will issue an error.

For more background on the format for specifying sessions, windows and panes within a tmux command, see the section COMMANDS in man tmux.

4
  • 26
    There's a simpler procedure: mark the pane with <prefix>m, go to the destination window with <prefix>w and move the marked pane there with join-pane.
    – Dan Aloni
    Commented Jan 31, 2018 at 15:32
  • Sadly it seems there is no such way (using marks, without naming it explicitly) to move a window.
    – doak
    Commented Feb 10, 2021 at 13:55
  • 1
    I like the way you referenced the manpage, but why didn't you just use man tmux | less '+/move-pane'?
    – doak
    Commented Feb 10, 2021 at 14:00
  • 1
    Even if it's not relevant, just want to add that you can also move whole windows by just replacing 'move-pane' with 'move-window'.
    – ds-bos-msk
    Commented Mar 11, 2021 at 17:15
10

I can't comment, so I will place it here: for tmux 2.1-3build1~precise the command should be:

<prefix>:move-pane -t session_name:window_number

-- you need a "-t" before session name (not necessarily a number), and the window with a given number must exist.

All the rest is as described by the_velour_fog in his answer.

P.S. If you type only a session_name without window_number like so:

<prefix>:move-pane -t session_name:,

then your pane will be moved into current window of destination session (and this window will be split).

P.P.S. If you just want to move your window (and not just your pane), then there a good answer on how to Move window between tmux clients:

<prefix>:move-window [-d] [-s src-window] [-t dst-window]

(alias: movew)

where src-window and dst-window have the form session:window.pane.

-1

I have two sessions running, each in their own iTerm. All I needed to do to move the pane from one session to another was

select the pane

<leader>s <session>

where <session> is a number inside square brackets

tmux 2.7

1
  • That doesn't actually move the pane from one session to another. That just changes the session you're viewing from the current terminal. It's equivalent to disconnecting and connecting to the other session. I want to actually be able to move panes between sessions with multiple other panes open.
    – HEGX64
    Commented Sep 9, 2018 at 8:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .