5

Let's say I have 3 panes opened in my tmux session, laid out like this:

|----|--|--|
| 1  | 2| 3|
|----|--|--|

What I would like to do, is flip this layout horizontally, so it looks like this:

|--|--|----|
| 3| 2| 1  |
|--|--|----|

Is there an easy way (preferably a shortcut) to do this?

8
  • Is pane 1 larger than the other two panes and if yes, does that need to be conserved?
    – pfnuesel
    Commented Sep 8, 2017 at 11:17
  • I have posted an answer, but I admit, it's not a very good one. Looking forward to better answers!
    – pfnuesel
    Commented Sep 8, 2017 at 11:28
  • Yes, precisely, I'm looking for a way to preserve the pane size. Right now I have a docking station which makes my two monitors merge into one display in xrandr. This means that I often have one terminal window spread across both of those monitors. Commented Sep 8, 2017 at 11:59
  • I understand. Wouldn't it make more sense to have two desktops, for two monitors, instead of a large one? Is there a specific reason why you want to have one desktop only? What windows manager do you use?
    – pfnuesel
    Commented Sep 8, 2017 at 12:06
  • I have one desktop because of hardware limitations, not choice :). I use i3wm, so one terminal window spread across both displays is a must (alt+enter shortcut, etc.) Commented Sep 8, 2017 at 13:14

2 Answers 2

6

A swap-pane -s 0 -t 2 will swap the source and target panes for you, leaving the one in the middle unchanged.

You could then write a small script to call list-panes which will tell you the current sizes, eg

0: [40x23] [history 2/2000, 760 bytes] %0 (active)
1: [19x23] [history 2/2000, 466 bytes] %3
2: [19x23] [history 2/2000, 466 bytes] %4

and then issue resize-pane commands for each pane to set a new size in the x direction. For example, create /tmp/myscript with

#!/bin/bash
tmux swap-pane -s 0 -t 2
tmux list-panes |
awk '
$1~/^[0-9]:$/ { x[$1] = substr($2,2)+0 }
END { print "tmux resize-pane -t 0 -x " x["2:"]
      print "tmux resize-pane -t 1 -x " x["1:"]
      print "tmux resize-pane -t 2 -x " x["0:"] }' |
sh

and do chmod +x /tmp/myscript, then add to your ~/.tmux.conf a binding such as for letter o, typed after your usual prefix key:

bind-key o run-shell /tmp/myscript
0
6

You can use the swap-pane command. By default this is bound to C-b { and C-b }, assuming C-b is your tmux prefix.

In your specific case, you can focus on pane 1, and do C-b } twice. Then you focus on pane 3 and do C-b { once.

There are many ways to achieve this, you can also use C-b C-o, no matter where your focus is, and then focus on pane 3 and do C-b {.

If you happen to do this often, you can make a shortcut in your ~/.tmux.conf.

Note, that none of these commands preserve the size of your panes. If the left pane used to be larger than the other two, that will still be the case after moving panes around. That means pane 1 will become smaller and pane 3 will grow larger. I don't know if it's possible to conserve pane sizes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .