You know how tmux panes are these isolated little worlds, right? Well, when you try to yank something from one pane to another, it feels like you’re trying to push a message in a bottle across two separate oceans – it usually just ends up in the void.

Here’s what’s actually happening: tmux has its own internal buffer, and by default, when you "yank" something (using v in copy mode, then y), it goes into that buffer. It doesn’t automatically know about your system’s actual clipboard (the one your mouse and other applications use). So, when you try to paste (p) in a different pane, you’re pasting from tmux’s internal buffer, not your system’s clipboard, hence the disconnect.

This is how you bridge that gap and make tmux’s yank and paste actually talk to your system’s clipboard.

The Problem: Tmux’s Internal Buffer vs. System Clipboard

Tmux maintains its own buffer history. When you enter copy mode (usually Ctrl-b [), navigate, and then yank (y), that text is stored in tmux’s buffer. Pasting (Ctrl-b ]) retrieves from this same buffer. This is great for copying within tmux, but it’s a walled garden when you want to interact with the outside world (your desktop’s clipboard).

The Solution: Integrating with xclip or pbcopy/pbpaste

The standard way to make tmux clipboard-aware is to pipe its buffer to an external utility that can interact with the system clipboard.

For Linux (X11/Wayland): xclip

If you’re on Linux, the common tool is xclip. You’ll need to install it first:

sudo apt update && sudo apt install xclip # Debian/Ubuntu
sudo dnf install xclip # Fedora

Then, you need to configure tmux to use it. The key is to bind keys that pipe the yanked content to xclip.

Configuration:

Add these lines to your ~/.tmux.conf:

# Set prefix to Ctrl-b
set-option -g prefix C-b
bind-key C-b send-prefix

# Copy mode bindings
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"
bind-key -T copy-mode-vi Y send-keys -X copy-pipe-and-cancel "xclip -selection clipboard"

Explanation:

  • bind-key -T copy-mode-vi y: This binds the y key specifically within copy mode (using vi-style keybindings, which is common).
  • send-keys -X copy-pipe-and-cancel "xclip -selection clipboard": This is the magic.
    • copy-pipe-and-cancel: This tmux command copies the selected text, pipes it to the specified command, and then exits copy mode.
    • "xclip -selection clipboard": This pipes the yanked text to xclip, telling it to put the text into the clipboard selection (the one usually used by Ctrl-C/Ctrl-V).

How to Use:

  1. Enter copy mode: Ctrl-b [
  2. Navigate to the start of the text you want to copy.
  3. Press v to start selection.
  4. Navigate to the end of the text.
  5. Press y. The text is now in your system clipboard.
  6. Switch to another pane (Ctrl-b <arrow key>).
  7. Paste using your system’s paste shortcut (e.g., Ctrl-Shift-v in many terminals, or Ctrl-v if your terminal maps it).

For macOS: pbcopy

macOS has built-in utilities for this: pbcopy and pbpaste.

Configuration:

Add these lines to your ~/.tmux.conf:

# Set prefix to Ctrl-b
set-option -g prefix C-b
bind-key C-b send-prefix

# Copy mode bindings
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
bind-key -T copy-mode-vi Y send-keys -X copy-pipe-and-cancel "pbcopy"

Explanation:

This is identical to the xclip setup, but it uses pbcopy which directly interfaces with the macOS pasteboard.

How to Use:

  1. Enter copy mode: Ctrl-b [
  2. Select text with v.
  3. Press y. The text is now in your macOS clipboard.
  4. Switch panes.
  5. Paste with Cmd-v.

For Windows (WSL): clip.exe

If you’re using Windows Subsystem for Linux (WSL), you can often use the Windows clip.exe command.

Configuration:

Add these lines to your ~/.tmux.conf:

# Set prefix to Ctrl-b
set-option -g prefix C-b
bind-key C-b send-prefix

# Copy mode bindings
bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "clip.exe"
bind-key -T copy-mode-vi Y send-keys -X copy-pipe-and-cancel "clip.exe"

Explanation:

Similar to the others, clip.exe is the Windows command-line utility for interacting with the clipboard.

How to Use:

  1. Enter copy mode: Ctrl-b [
  2. Select text with v.
  3. Press y. The text is now in your Windows clipboard.
  4. Switch panes.
  5. Paste with Ctrl-v (in your Windows terminal application).

Reloading Tmux Configuration

After editing ~/.tmux.conf, you need to tell tmux to reload it. You can do this by:

  1. Pressing Ctrl-b : to enter tmux command mode.
  2. Typing source-file ~/.tmux.conf and pressing Enter.

Or, if you’re already in copy mode, you can use Ctrl-b r (if you have bind-key r source-file ~/.tmux.conf in your config).

The "Other" Paste: Ctrl-b ]

It’s crucial to understand that after setting up xclip or pbcopy, the default tmux paste command (Ctrl-b ]) will still paste from tmux’s internal buffer, not the system clipboard. If you want to paste from the system clipboard using a tmux keybinding, you’ll need to bind a new key for that.

Example for Linux:

Add this to your ~/.tmux.conf:

bind-key P paste-buffer # Bind Ctrl-b P to paste from tmux buffer
bind-key p run-shell "xclip -selection clipboard -o" # Bind Ctrl-b p to paste from system clipboard

Now:

  • Ctrl-b ] pastes from tmux’s internal buffer.
  • Ctrl-b p pastes from your system clipboard.

The Counterintuitive Part: Why copy-pipe-and-cancel?

The copy-pipe-and-cancel command is more than just a simple pipe. It captures the selected region, sends it to the specified external command, and crucially, exits copy mode. If you used a simpler pipe command, you’d pipe the text but remain in copy mode, which is often not what you want. The -cancel suffix ensures a clean exit from the selection state, allowing you to immediately paste or continue working.

The Next Step: Syncing Buffers Bidirectionally

Once you have copy-paste working, you might wonder if you can get tmux to automatically sync its primary buffer (the one Ctrl-b ] pastes) with the system clipboard, so you don’t have to remember y for yank-to-clipboard vs. Y for just tmux-buffer-yank, or Ctrl-b ] vs. a new keybind for system paste. This often involves more complex scripting or dedicated tmux plugins.

Want structured learning?

Take the full Tmux course →