37

how can I grab a window from totally different tmux session and attach it as a horizontal/vertical split to current window?

2 Answers 2

48

Sounds like you're looking for join-pane. Technically for the second part of your question you want to join a pane to the current window, not the full window from the other session since that could include multiple panes.

Here's an example. Let's say you're in session 0, window 4 and in session 2 that you want window 3's pane 1. In the tmux prompt (ctrl+b : by default)

join-pane -s 2:3.1

This will move pane 1 from window 3, session 2 (-s is the source window and takes the format session:window.pane) to your current session (session 0).

Below are the full docs for join-pane, which you can get from the tmux man page. The most confusing part for me reading the docs was figuring out the format that was expected for src-pane specifying session, window and pane numbers (session:window.pane per the example above). You can also name your sessions and windows and use those names instead of the index numbers.

 join-pane [-dhv] [-l size | -p percentage] [-s src-pane] [-t dst-pane]
   (alias: joinp)
   Like split-window, but instead of splitting dst-pane and 
   creating a new pane, split it and move src-pane into the 
   space.  This can be used to reverse break-pane.
3
  • 9
    Can I copy a pane instead of moving it?
    – pielgrzym
    Apr 27, 2011 at 16:57
  • @pielgrzym I'd love to know the answer to that too. Please post it here if you find it. Feb 1, 2012 at 16:29
  • 1
    I think OP was looking for something more like link-pane, which unfortunately doesn't exist. Apparently the requested behavior can be mimicked using nested tmux socket, as is explained here: superuser.com/a/323658
    – elig
    Jun 20, 2019 at 22:23
17

If you are trying to join panes from within the same session, you will instinctively want to omit the "session:" from the command. This will fail. It seems that the -s and -t switches to join-pane accept the argument in the form of [session]:window[.pane] instead of [session:]window[.pane]

That is to say, the session is optional and the : is mandatory. This is goofy. It would be the equivelent of browsers requiring http://google.com:/ as the shortcut version of http://google.com:80/ and giving an error to http://google.com/ o_O

Since ctrl-b ! breaks the current pane into a separate window (which is the opposite of what we want to do), and ctrl-b @ (which is right beside !) is unbound by default (meaning you are not overwriting anything) I suggest creating this shortcut...

bind-key @ command-prompt -p "create pane from:"  "join-pane -s ':%%'"
0

You must log in to answer this question.

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