How to rotate panes in tmux?

Quick Answer

To rotate panes in tmux, use the rotate-window command. Press Ctrl+b } to rotate panes clockwise or Ctrl+b { to rotate counterclockwise. These commands swap the positions of panes while maintaining their content, allowing you to quickly rearrange your workspace without changing the layout structure.

# Rotate clockwise
Ctrl+b }

# Rotate counterclockwise
Ctrl+b {

Detailed Explanation

Rotating panes in tmux allows you to quickly rearrange your workspace without affecting the content of each pane or the overall layout structure. This is particularly useful when you want to optimize your view based on the current task or bring a specific pane into a more convenient position.

Default Keybindings

tmux provides two default keybindings for rotating panes:

  • Ctrl+b } - Rotate panes clockwise
  • Ctrl+b { - Rotate panes counterclockwise

When you press these key combinations, the panes will shift positions while maintaining their content and size. The rotation happens in the order the panes were created, not necessarily in visual order.

Command Line Method

You can also rotate panes using the tmux command prompt:

# Enter command mode with Ctrl+b :, then type:
rotate-window -D  # Rotate clockwise (Down)
rotate-window -U  # Rotate counterclockwise (Up)

The -D flag rotates clockwise (Down), and -U rotates counterclockwise (Up). These commands correspond to the } and { keybindings respectively.

How Pane Rotation Works

To understand how rotation works, consider this example of a window with three panes arranged vertically:

┌──────┬──────┐
│  A   │  B   │
│      │      │
├──────┘      │
│  C          │
│             │
└─────────────┘

After pressing Ctrl+b } (clockwise rotation), the panes would rearrange to:

┌──────┬──────┐
│  C   │  A   │
│      │      │
├──────┘      │
│  B          │
│             │
└─────────────┘

The content and relative size of each pane remains the same, but their positions have shifted.

Custom Keybindings

If you find yourself rotating panes frequently, you might want to set up more intuitive keybindings in your ~/.tmux.conf file:

# More intuitive pane rotation keybindings
bind-key r rotate-window -D  # Ctrl+b r to rotate clockwise
bind-key R rotate-window -U  # Ctrl+b R to rotate counterclockwise

Limitations and Considerations

There are a few things to keep in mind when rotating panes:

  • Rotation works best with simple layouts. Complex nested layouts might not rotate as expected.
  • Rotation maintains the layout structure but changes pane positions.
  • If you want to completely rearrange panes, consider using the select-layout command instead.
  • Rotation affects all panes in the current window, not just a subset.