Moving tmux pane to window

The command to do this is join-pane in tmux 1.4.

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.

To simplify this, I have these binds in my .tmux.conf for that:

# pane movement
bind-key j command-prompt -p "join pane from:"  "join-pane -s '%%'"
bind-key s command-prompt -p "send pane to:"  "join-pane -t '%%'"

The first grabs the pane from the target window and joins it to the current, the second does the reverse.

You can then reload your tmux session by running the following from within the session:

$ tmux source-file ~/.tmux.conf

join-pane is the answer. I too was having problems with my attempts to use it based on the tmux documentation. I discovered that the -t and -s switches seem to accept [session]:window and not [session:]window. That is to say that specifying the session is optional, but including the : is mandatory. (I am using tmux 1.5)

Therefore, in order to add a pane to the current window and place window 1 into the pane, the command would be (Ctrl+B or whatever your bind key is, followed by)...

:join-pane -s :1

You can then break them apart with break-pane which by default is: Ctrl+B ! If you want to bind it to a shortcut, I suggest NOT overriding a default binding like s, because down the road you will look on the internet for an answer that involves choose-session and it will not work on your system. Notice that break-pane is bound to ! and @ is right next to it and not bound to anything by default. For that reason I suggest this binding...

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

Alternately, to have an interactive chooser...

bind-key   @ choose-window 'join-pane -h -s "%%"'
bind-key C-@ choose-window 'join-pane    -s "%%"'

Alternately, to always join the most recently visited window...

bind-key @ join-pane -h -s !

NOTE: The -h causes it to stack the panes horizontally (with a vertical split) as opposed the default behavior which is the reverse.

The most important thing is that your LEARN whatever you choose to shortcut. Because if you just set it and forget it, you will be gimped when you find yourself on a foreign server. And let's face it, the most important thing a terminal multiplexer gives you is reliable sessions on remote servers.

This completes my conversion from GNU Screen to Tmux. I'll never look back.

Enjoy!


I think I like what I've been using for moving panes to their own window better. I use

break-pane -t :

I figured it out through experimentation, but it seems to work very well. You can keybind or alias it easily, no scripting required.

Tags:

Tmux