Tmux: How can I link a window as split-window?
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.
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 ':%%'"