0

How do you swap one large tmux pane with several smaller ones?
In other word: from an arrangement like A – to an arrangement like B:

                  AB
      ┏───────────────────────┓         ┊         ┌───────┬───────┬───────┐
      │                       │         ┊         │       │       │       │ 
      │           1           │         ┊         │   2   │   3   │   4   │
      │                       │         ┊         │       │       │       │
      ┡───────┬───────┬───────┩         ┊         ┢───────┴───────┴───────┪
      │       │       │       │         ┊         │                       │ 
      │   2   │   3   │   4   │         ┊         │           1           │ 
      │       │       │       │         ┊         │                       │ 
      └───────┴───────┴───────┘         ┊         ┗───────────────────────┛

There are plenty of resources covering similar operations, but not quite this.

  • / / / moves the focus to another pane.
  • alt + / / / adjusts their dimensions.
  • Space cycles various pane layouts / arrangements.
  • { / } shoves individual panes left / right – but that just forces a direct swap, like:
                  AC
      ┏───────────────────────┓         ┊         ┌───────────────────────┐
      │                       │         ┊         │                       │ 
      │           1           │         ┊         │           2           │
      │                       │         ┊         │                       │
      ┡───────┬───────┬───────┩         ┊         ┢───────┱───────┬───────┤
      │       │       │       │         ┊         │       │       │       │ 
      │   2   │   3   │   4   │         ┊         │   1   │   3   │   4   │ 
      │       │       │       │         ┊         │       │       │       │ 
      └───────┴───────┴───────┘         ┊         ┗───────┹───────┴───────┘
1
  • Note, if you are doing this a lot for 2 fixed layouts, once you have the 2 layouts you can save them to a file and toggle between them. See similar question on stackoverflow.
    – meuh
    Oct 2, 2019 at 8:03

1 Answer 1

1

Use the -f option of tmux split-window. The new pane will span the full window height (with -h) or full window width (with -v).

  1. Create a new pane at the very bottom:

    tmux split-window -vf
    
  2. Invoke tmux display-panes (or prefix,q) to identify the two panes you want to swap: the top one and the bottom one.

  3. Let's say these panes are 0 and 3. Swap them:

    tmux swap-pane -s 0 -t 3
    

    Or you can mark one pane (RMB) and run just tmux swap-pane in the other.

  4. Destroy the top pane.


Or run this in the top pane:

tmux split-window -vf "tmux swap-pane -dt '$TMUX_PANE'"

To "undo" (i.e. "move" large bottom pane to top) run this in the bottom pane:

tmux split-window -vfb "tmux swap-pane -dt '$TMUX_PANE'"

Or mark the top pane (RMB), open the tmux command prompt (prefix,:) and execute this:

split-window -vf "tmux swap-pane -d"

This is useful when your top pane is busy and you cannot execute commands in a shell there.

You must log in to answer this question.

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