Skip to content
kilofoxPublic

About

Reorder tmux windows and swap panes by dragging them with your mouse

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

Repository files navigation

tmux-drag

tmux-drag demo

Reorder tmux windows by dragging their tabs in the status line, and swap tmux panes by dragging them in the pane area.

Windows are swapped as the pointer crosses their tabs. The active window does not change while dragging, so you can move a tab across several others and reverse direction before releasing it. A normal click still selects a window or pane.

Requirements

  • tmux 3.2 or newer
  • mouse enabled in tmux
  • A terminal that sends mouse drag events

Installation

TPM

set -g @plugin 'rockofox/tmux-drag'

Press prefix + I to install it.

Manual

Load the entrypoint from your tmux configuration:

run-shell '/path/to/tmux-drag/tmux_drag.tmux'

The plugin adds mouse bindings and wraps the existing window status formats with tmux status ranges. It does not replace the status-line styling provided by another plugin.

Make sure mouse is enabled before loading the plugin:

set -g mouse on

Use

Reordering tabs

  1. Press and hold the left mouse button on a window tab.
  2. Move the pointer across the tabs you want to cross in the status line.
  3. Release the button.

Each crossed tab swaps places with the dragged window. The active window does not change while dragging, and the final tab is selected on release. A normal click still selects a window.

Converting tabs to splits

  1. Press and hold the left mouse button on any window tab in the status line.
  2. Drag the pointer up out of the status line into a pane.
  3. Release the button inside the target pane.

The window tab is converted into a split pane inside your active window. The split direction is chosen based on where you drop:

  • Drop near the left edge to split to the left.
  • Drop near the right edge to split to the right.
  • Drop near the top edge to split above.
  • Drop near the bottom edge to split below.

If the tab contained multiple panes, all panes are moved into the destination window and the source tab closes.

To cancel the drag, drag the pointer back onto the status line or release over status margins.

Swapping splits

To swap splits without interfering with normal terminal mouse behavior:

  1. Hold Ctrl, then press and hold the left mouse button inside a pane.
  2. Move the pointer into another pane, in the same window or another window.
  3. Release the button.

Each crossed pane swaps places with the dragged pane. Pane sizes and layouts remain under tmux's control. Without Ctrl, tmux and the terminal retain their normal pane selection, text selection, and border resizing behavior.

Configuration

You can tweak the split behavior in your tmux configuration:

# Force a fixed split direction instead of auto quadrant detection:
# options: auto (default), horizontal, vertical, left, right, top, bottom
set -g @tmux-drag-tabs-split-direction 'auto'

# When dragging a multi-pane tab, 1 moves all panes and closes the tab.
# Set to 0 to move only the active pane from that tab:
set -g @tmux-drag-tabs-split-all-panes 1

Why use the plugin?

tmux can provide basic tab dragging with a binding such as the one discussed in tmux issue #656:

bind-key -n MouseDrag1Status swap-window -d -t=

This plugin uses the same tmux swap-window primitive, but adds a more complete drag interaction:

  • Records the window where the drag started instead of relying on tmux's implicit current window.
  • Swaps only when entering a new tab, avoiding repeated swaps while hovering over the same tab.
  • Keeps the active window stable while dragging across multiple tabs.
  • Selects the final tab when the mouse button is released.
  • Preserves existing status-line styling while adding the ranges needed to identify tabs reliably.
  • Installs the bindings and manages drag state automatically.

The one-line binding is still a good choice if you want the smallest possible configuration and basic drag-to-reorder behavior. This plugin is intended for predictable multi-tab drags without manual mouse-binding setup.

Development

Run the test suite from the repository root:

./tests/test.sh

The tests create a separate tmux server and socket, so they do not touch the tmux server used by your terminal.

Limitations

  • Drag state is scoped to a session. Two clients dragging tabs or panes in the same session at the same time are not supported.
  • Linked windows in other sessions are not reordered.
  • Pane swaps across linked windows or sessions are not supported.
  • Dragging a zoomed pane may still be handled by tmux as a zoom operation.
  • Nested tmux sessions and terminals that do not forward drag events may interfere with mouse input.

About

Reorder tmux windows and swap panes by dragging them with your mouse

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages