Skip to main content
Browse referenceCopy and Paste

Copy and Paste in tmux

Get text out of terminal scrollback and into the place you need it, with separate checks for tmux and your system clipboard.

Verified Sep 2026 for tmux 3.7c
7 min read
intermediate

Outcome: copy a line from scrollback, verify its tmux buffer, then test pasting into a desktop app. You need tmux installed and a real terminal. Ctrl+b [ means press and release Ctrl+b, then press [. These instructions assume the default prefix.

Copy between tmux panes

tmux keeps its own paste buffers. A successful copy there does not by itself prove that your operating system clipboard changed.

  1. In a tmux shell, print a harmless line with printf 'tmux-copy-check\n'.
  2. Check the current copy keys with tmux show-options -w mode-keys.
  3. Press Ctrl+b [ and use the arrow keys to move to the start of tmux-copy-check in the output.
  4. With mode-keys emacs, press Ctrl+Space to start selecting, move across the text, then press Alt+w to copy. With mode-keys vi, use Space to start selecting and Enter to copy. These copy commands leave copy mode.
  5. Run tmux show-buffer. You should see the selected text. Switch to a scratch editor in another pane and press Ctrl+b ] to paste it. Ctrl+b = opens a chooser for older buffers.

Paste into an editor for this check: copied text can contain newlines that a shell treats as commands. Copy mode and buffer commands are documented in the tmux 3.7c manual.

Prefer mouse selection or vi navigation? Open the clipboard config preset, review the generated settings, and merge the ones you want into your configuration. That preset configures tmux input; it cannot enable your terminal's system clipboard permissions.

Copy to the system clipboard over SSH

OSC 52 lets a terminal receive copied text through terminal output, including over SSH. It requires support and permission in the local terminal application as well as clipboard support in the tmux instance running on the remote host. See the official clipboard guide.

From a shell inside the tmux session, inspect:

bash
tmux show-options -s set-clipboard
tmux info | grep 'Ms:'

set-clipboard external allows tmux copies to reach the terminal without accepting clipboard-setting sequences from applications inside tmux. If it is off, this line in ~/.tmux.conf enables that behavior:

tmux
set -s set-clipboard external

Apply the edited file with tmux source-file ~/.tmux.conf. Check your local terminal's documentation for OSC 52 or clipboard-write permission. An Ms value of [missing] means tmux also needs a matching terminal capability. Inspect printf '%s\n' "$TERM" outside tmux, then follow the wiki's terminal-features instructions for that exact terminal. Only declare clipboard support if the terminal supports it; a configuration line cannot add the feature to the terminal.

Verify: repeat the copy-mode selection above, open a plain text editor on your local computer, and use its normal Paste action. Seeing tmux-copy-check there confirms the full path. Pasting from your desktop clipboard into tmux uses your terminal application's ordinary Paste action; Ctrl+b ] reads a tmux buffer.

Use a local clipboard helper

For tmux running on your own Mac, a clipboard helper is another option. For example, bind y in vi copy mode to the built-in pbcopy program:

tmux
set -g mode-keys vi
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel 'pbcopy'

Reload the configuration, select text with Space in copy mode, then press y. On an X11 desktop, the corresponding helper may be xclip -selection clipboard -i if installed and connected to the desktop display. Helpers run on the machine hosting tmux: pbcopy on a remote host does not reach your laptop clipboard. The official external-tool instructions explain the alternatives.

If copying still fails

  • No tmux buffer: check mode-keys and custom bindings with tmux list-keys -T copy-mode or tmux list-keys -T copy-mode-vi. The failure precedes clipboard integration.
  • Buffer works, desktop paste does not: check set-clipboard, Ms, and terminal permissions separately. Try one short line; terminal clipboard limits vary.
  • Local tmux contains remote tmux: there are two clipboard boundaries. Start with a direct SSH connection outside local tmux. The wiki documents the additional configuration for nested tmux.
  • Mouse selects panes instead of terminal text: with tmux mouse mode enabled, selection belongs to tmux. Your terminal may offer a modifier key to bypass mouse reporting; check that terminal's settings.

Practice and continue

Practice copy mode to learn the keys, or explore the playground. Both are browser simulations; they cannot verify your desktop clipboard, SSH connection, or terminal permissions. Run the checks above in a real terminal, then use the config validator to inspect configuration text.

Next: keep a remote session running or build a development workspace.