How to Copy Selected Text in Tmux

Tmux is a powerful terminal multiplexer — it lets you split your terminal into multiple panes, run persistent sessions, and navigate complex workflows without losing your place. But one area that trips up nearly every new user is copying and pasting text. Unlike a standard terminal, tmux intercepts mouse and keyboard input through its own layer, which means copying text requires a slightly different mental model.

Here's a clear breakdown of how text copying works in tmux, what variables affect the process, and why the right approach depends on your specific setup.

Understanding Tmux's Copy Mode

Tmux has a built-in feature called copy mode, which lets you scroll back through terminal output and select text without using your mouse. Think of it as a read-only view of your terminal history where you can highlight and yank (copy) content.

To enter copy mode, press:

Prefix + [ 

The prefix key is Ctrl+b by default, though many users remap it to Ctrl+a. Once in copy mode, your terminal becomes navigable like a text editor — you can scroll, search, and select.

The Two Keybinding Modes: vi vs. Emacs

This is where most confusion starts. Tmux supports two keybinding styles for copy mode:

ModeSelect TextCopy (Yank)
vi modeSpace to start, move cursor to extendEnter to copy
Emacs modeCtrl+Space to start, move cursorAlt+w to copy

By default, tmux uses Emacs-style bindings unless you explicitly set vi mode. To check or set your preference, look at your ~/.tmux.conf file:

set-window-option -g mode-keys vi 

Adding that line switches copy mode to vi keybindings. Without it, you're working with Emacs bindings — which is fine, just different.

Step-by-Step: Copying Text with Vi Mode 🖱️

Once mode-keys vi is set in your config:

  1. Press Prefix + [ to enter copy mode
  2. Navigate to the start of the text you want (arrow keys, hjkl, Ctrl+u/Ctrl+d for page scroll)
  3. Press Space to begin selection
  4. Move the cursor to extend the highlight
  5. Press Enter to copy the selected text into tmux's clipboard buffer
  6. Exit copy mode (it exits automatically after copying, or press q)
  7. Press Prefix + ] to paste

With Emacs bindings, substitute Space with Ctrl+Space and Enter with Alt+w.

Where Does the Copied Text Actually Go?

This is a critical variable that many guides skip over. Tmux maintains its own internal paste buffer — separate from your operating system's clipboard. When you copy text in copy mode, it goes into tmux's buffer, not your system clipboard.

That means:

  • Prefix + ] pastes within tmux ✅
  • Ctrl+V or right-click paste in another app may not work ❌

Whether or not tmux integrates with your system clipboard depends on your operating system and what additional tools you have installed.

Integrating with the System Clipboard

This is where your environment matters most.

On macOS, you can pipe copied text to pbcopy using a tmux binding in your config:

bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "pbcopy" 

On Linux with X11, the equivalent tool is xclip or xsel:

bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xclip -in -selection clipboard" 

On Linux with Wayland, use wl-copy instead:

bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "wl-copy" 

On WSL (Windows Subsystem for Linux), clip.exe is the bridge:

bind -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "clip.exe" 

None of these are automatic — each requires a deliberate configuration choice and the relevant tool installed on your system.

Mouse Support and Its Trade-offs 🖱️

Tmux can be configured to allow mouse-based text selection with:

set -g mouse on 

With mouse mode enabled, you can click and drag to highlight text. However, this changes behavior: by default, mouse-selected text may go to tmux's buffer rather than your system clipboard, depending on your terminal emulator.

Some terminal emulators (like iTerm2, Alacritty, or WezTerm) have their own clipboard handling that interacts with tmux's mouse mode in different ways. Holding Shift while selecting text often bypasses tmux entirely and lets the terminal emulator handle the copy — useful when you want standard clipboard behavior.

Variables That Affect Your Workflow

Several factors determine which approach works best for you:

  • Operating system — macOS, Linux (X11 vs. Wayland), or Windows (WSL) each require different clipboard tools
  • Terminal emulator — iTerm2, Alacritty, GNOME Terminal, Kitty, and others handle mouse and clipboard differently
  • Tmux version — older versions use different copy-mode syntax; copy-pipe-and-cancel was introduced in later releases
  • Keybinding preference — vi vs. Emacs mode is a personal workflow decision
  • Whether you use the mouse — mouse mode adds convenience but introduces clipboard complexity
  • tmux plugin manager (TPM) — plugins like tmux-yank automate system clipboard integration and abstract away OS-specific differences

The tmux-yank plugin, for example, automatically detects your OS and handles clipboard routing — which removes the need to write custom copy-pipe bindings manually.

The Gap in Getting It Right

The mechanics of copying text in tmux are consistent across environments — enter copy mode, select, yank, paste. But whether that text lands in your system clipboard, which key triggers the copy, and whether your mouse behaves the way you expect all come down to your specific combination of OS, terminal emulator, tmux version, and personal config.

Two developers using tmux daily can have entirely different setups that both work perfectly — just configured differently. Understanding what each layer does is the prerequisite for deciding which configuration matches your actual workflow.