Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move a window to another session in tmux?

In tmux, how can I move a window from a session to another session?

ex. move window:4 in session [0] to session [4] .

like image 995
黃郁暉 Avatar asked Dec 28 '17 02:12

黃郁暉


People also ask

How do I move a tmux window?

Pressing Ctrl+Shift+Left (will move the current window to the left.

How do I move tmux panes to a new window?

For breaking a pane to a new window, use break-pane (whichcanalsobebound).

How do I go to a specific tmux session?

Using the Prefixes to Control Tmux By default, the prefix is CTRL+B. That is, we have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session we need to press CTRL+B and next C – CTRL+B, C.


2 Answers

From my testing on tmux 2.6, you'll need two things for the command to move an entire window over:

  • The name of the session you want to move the window from (for future reference, $session_name)
  • The index of the window you want to move (in the session it's currently in, of course -- we'll call this $window_index). This is actually optional -- if you omit this, then it defaults to the window in focus in the session you're pulling the window from.

From this point, you can just change to the session you want to move the window into, <tmux-escape>: into a command prompt, and type a command of this form:

move-window -s $session_name[:$window_index]

...where, as noted before, the $window_index is optional (as indicated by the square brackets, which aren't actually part of the syntax ). To use some concrete examples:

move-window -s $session_name # Moves from currently-focused window from session named `$session_name` 

move-window -s $session_name:$window_index # Moves from window with index `$window_index` from session named `$session_name` into the current session

Et voilà! Your window got moved. :)

EDIT: Added some more info on an alternative that omits $window-index.

like image 104
Erich Gubler Avatar answered Oct 12 '22 11:10

Erich Gubler


There's now a built-in shortcut <tmux-escape>. to bring up the move-window command, so it's as easy as <tmux-escape>. <session_name>:<window_index> or to move a window within the same session, omit the session name: <tmux-escape>. <window_index>

like image 4
iforwms Avatar answered Oct 12 '22 11:10

iforwms