Tmux: How to link a window as split-window


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

Best Answer

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.