I don't know how to mirror an arbitrary layout, but in case of C-b, M-4
it's not that hard.
The tmux command bound to C-b, M-4
is select-layout main-vertical
.
To get from main-vertical
to the layout you want, this is what we need to do:
- Create a new pane spanning the full window height on the right.
- Swap the new pane with the leftmost pane.
- Destroy the leftmost pane.
This is my implementation (to run in a shell inside tmux):
tmux select-layout main-vertical \;\ split-window -dhf '' \;\ swap-pane -d -s {right} -t {left} \;\ kill-pane -t {left}
The above code transforms your first diagram into the second one. It also works well with more panes stacked vertically on the right. It reasonably works with any layout and creates a mirrored main-vertical
from it.
I notice select-layout main-vertical
is idempotent, but the above code is not. It would be nice to have an idempotent version of our command. This is it:
tmux rotate-window -D \;\ select-pane -t {next} \;\ select-layout main-vertical \;\ split-window -dhf '' \;\ swap-pane -d -s {right} -t {left} \;\ kill-pane -t {left}
but it does not exactly transforms your first diagram into the second one, the sequence of panes is different.
In general none of these behaves nicely when used alternately with plain select-layout main-vertical
; I mean the big pane is not the same pane when you transform back and forth. Note that select-layout main-vertical
always makes the top-left pane big, so it simply cannot transform your second diagram into your first. To fix this we would need some logic, not only in our code but also as a replacement for select-layout main-vertical
.
If I were you, I would use the first snippet. It's simpler than the other and it nicely transforms your first diagram into the second one. Idempotence is not that important; once you get the desired layout, you don't need to apply it again.
For me Shift+4 sends $
. To bind our first tmux command to prefixAlt+Shift+4 I put this into my ~/.tmux.conf
:
bind-key -T root M-\$ select-layout main-vertical \; split-window -dhf '' \; swap-pane -d -s \{right\} -t \{left\} \; kill-pane -t \{left\}