The basic way to copy text in tmux

Tmux uses its own clipboard system separate from your operating system's clipboard, so copying text requires a deliberate step. To copy selected text in tmux, you enter copy mode by pressing Ctrl+b followed by [ (the bracket key). Once in copy mode, you can move your cursor with arrow keys, select text with Spacebar to start and Enter to copy, then paste it back into tmux with Ctrl+b followed by ].

This workflow keeps copied text inside tmux sessions, which is useful when you are working across multiple terminal windows or remote servers. The text stays available even if you detach from the session and come back later.

Key Takeaways

  • Enter copy mode with Ctrl+b then [ to select and copy text within tmux.
  • Use Spacebar to start selection, arrow keys to move, and Enter to copy the highlighted text.
  • Paste copied text back into any tmux window with Ctrl+b then ].
  • Tmux keeps copied text in its own buffer, separate from your system clipboard, so you cannot paste it directly into other applications without extra configuration.
  • You can configure tmux to send copied text to your system clipboard using tools like xclip on Linux or pbcopy on macOS.

Step-by-step copying in copy mode

Start by pressing Ctrl+b then [. Your cursor will move to the top-left of the window and you will see a small indicator showing you are in copy mode. Use the arrow keys to navigate to the beginning of the text you want to copy.

Once your cursor is positioned, press Spacebar. This marks the start of your selection. Now use arrow keys to move to the end of the text you want. As you move, the selected text will highlight (usually in white or a contrasting color). When the selection covers what you need, press Enter. Tmux copies the selected text to its internal buffer and exits copy mode automatically.

To paste the text you just copied, press Ctrl+b then ]. The text will appear at your cursor position in the current tmux window. You can paste the same text multiple times — it stays in the buffer until you copy something new.

Copying text to your system clipboard

By default, text copied in tmux stays inside tmux and cannot be pasted into other applications like your text editor or email client. To send copied text to your operating system's clipboard, you need to configure tmux to use a system tool.

On Linux, add this line to your tmux configuration file (usually ~/.tmux.conf):

bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xclip -i -sel clipboard"

On macOS, use this instead:

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

After adding the line, reload your tmux configuration by pressing Ctrl+b then : and typing source-file ~/.tmux.conf, then Enter. Now when you select text in copy mode and press y (instead of Enter), the text goes to both your tmux buffer and your system clipboard. You can then paste it into any process with Ctrl+v or Cmd+v.

Using vi or emacs key bindings for faster copying

Tmux supports different key binding styles. If you use vi key bindings (which many terminal users prefer), you can select and copy more quickly. Add this to your ~/.tmux.conf:

setw -g mode-keys vi

With vi bindings enabled, you can use v to start selection instead of Spacebar, and y to copy instead of Enter. This matches the behavior of vi and vim, so if you already know those editors, the keys will feel natural. You still enter copy mode the same way: Ctrl+b then [.

If you prefer emacs key bindings, tmux uses those by default, so you do not need to change anything. The Spacebar and Enter approach described earlier is the emacs style.

Selecting entire lines or words quickly

When you need to copy more than a few characters, selecting word by word or line by line is faster than holding arrow keys. In copy mode with vi bindings, press w to select the next word, or b to select backward one word. Press $ to select to the end of the line, or ^ to select to the beginning.

With emacs bindings (the default), use Meta+f (Alt+f on most keyboards) to move forward one word, or Meta+b to move backward one word. These movements work in selection mode too, so you can position your cursor faster without tapping arrow keys repeatedly.

Viewing and managing your copy buffer

Tmux keeps a history of text you have copied. To see what is currently in your buffer, press Ctrl+b then #. A list will appear showing recent copies. Use arrow keys to highlight the text you want and press Enter to paste it. This is useful if you copied something, then copied something else, but now want the first text back.

The buffer history is limited by default (usually the last 20 copies), but you can increase it by adding this to ~/.tmux.conf:

set -g buffer-limit 50

This keeps the last 50 copied items instead of 20. After reloading your configuration, you will have more history to work with when you need to retrieve an older copy.

Troubleshooting common copying problems

If copy mode does not seem to work, check that you are using the correct prefix key. The default is Ctrl+b, but some people rebind it. Look at the top of your ~/.tmux.conf file for a line like set -g prefix C-a — if it exists, use that key instead of Ctrl+b.

If text is not highlighting when you select it, your terminal may not support the color output tmux is trying to use. Try pressing q to exit copy mode and then check your terminal's color settings. If copied text is not appearing when you paste, make sure you pressed Enter (or y with vi bindings) to actually copy — just selecting text does not copy it unless you confirm with one of those keys.

If you configured tmux to copy to your system clipboard but it is not working, check that the tool exists on your system. On Linux, run which xclip in a terminal — if it returns nothing, install xclip using your package manager. On macOS, pbcopy comes built in, so if it is not working, reload your tmux configuration again.

Frequently Asked Questions

Can I copy text by dragging my mouse in tmux?

Yes, if you hold Shift while dragging your mouse, most terminals will select text without entering tmux copy mode. However, this selects text in your terminal emulator, not in tmux itself, so the behavior depends on your terminal process. For reliable copying that works the same way everywhere, use copy mode instead.

Why does my copied text disappear when I close the tmux window?

Tmux buffers are tied to individual sessions. When you close a window within a session, the buffer stays. When you close the entire session, the buffer is deleted. If you need to keep text across sessions, configure tmux to copy to your system clipboard so the text persists outside tmux.

How do I copy multiple lines at once?

In copy mode, position your cursor at the start of the first line and press Spacebar (or v with vi bindings). Then use arrow keys or word-jump commands to move to the end of the last line you want. The selection will span multiple lines. Press Enter (or y) to copy all of it.

Can I copy text from a tmux window that is scrolled up in history?

Yes. When you enter copy mode with Ctrl+b then [, you can scroll up and down through your window's history using Page Up and Page Down, or with arrow keys. Select and copy text from any point in the history the same way you would from the current view.

What is the difference between copying with Enter and copying with y?

Enter (emacs style) copies the text and stays in copy mode, so you can make another selection if you want. The y key (vi style) copies and exits copy mode when ready. Both end up with the same text in your buffer — the difference is just whether you stay in copy mode or leave it.