Epic
Epic

Reputation: 622

how to move Tmux panes

I like to work with 3 tmux panes. one horizontal pane at the upper half of the screen and two more panes at the bottom half. These panes are split vertically.

tmux pane image

There are cases where I would like to take the last pane and make it go from top to bottom. like this:

target tmux pane image

How can I achieve this? using [ctrl+b ctrl+o] and [ctrl+b space] did not reach the desired position and is cumbersome.

Upvotes: 4

Views: 2194

Answers (1)

meuh
meuh

Reputation: 12255

There is probably an easier way, but what you can do is arrange the panes manually in each of the two configurations, noting each layout in a variable with e.g.:

layout1=$(tmux list-windows -F '#{window_layout}')

This holds a string something like:

5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]

which you must not alter in any way as the first number is a checksum of the rest of the string.

Once you have the two strings you can set a binding to set that layout using select-layout, or by giving the command from the shell where you have the variables:

tmux select-layout "$layout1"

You might find it easier to write a small helper script, say mtmux to toggle between the layouts:

#!/usr/bin/bash
# https://stackoverflow.com/q/56343223/5008284
# toggle between 2 layouts, previously saved
layout1='5f2f,80x23,0,0[80x11,0,0,0,80x11,0,12{39x11,0,12,1,40x11,40,12,2}]'
layout2='093c,80x23,0,0{39x23,0,0[39x11,0,0,0,39x11,0,12,4],40x23,40,0,3}'
layout="$(tmux list-windows -F '#{window_layout}')"
case "$layout" in
*80x11*)    new=$layout2 ;;
*)          new=$layout1 ;;
esac
tmux select-layout "$new"
tmux display-panes
exit 0

and have a binding, say control-L, to run this shell:

    bind-key -n C-l run-shell 'mtmux'

Upvotes: 5

Related Questions