Tmux copy mode key bindings are surprisingly powerful because they let you navigate and select text within your terminal sessions using familiar text editing paradigms, effectively turning your terminal into a mini-text editor.

Let’s see copy mode in action. Imagine you’re SSH’d into a server, running a long command, and you want to grab the output.

$ ssh user@remote-server
user@remote-server's password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-91-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

Last login: Mon Jan 22 10:30:00 2024 from 192.168.1.100

user@remote-server:~$ apt update && apt upgrade -y
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
... (lots of output) ...
Setting up openssh-server (1:8.9p1-3ubuntu0.4) ...
Processing triggers for man-db (2.10.2-1) ...
user@remote-server:~$

You want to copy the apt update && apt upgrade -y command.

First, enter copy mode. If you’re using Vi key bindings (the default), press Ctrl+b (your tmux prefix) then [ (open bracket). If you’re using Emacs key bindings, it’s Ctrl+b then Ctrl+[.

Once in copy mode, your terminal display will change slightly, often showing a cursor and perhaps a line count or mode indicator.

Vi Mode:

  • k and j: Move up and down lines.
  • h and l: Move left and right characters.
  • w and b: Move forward and backward by words.
  • 0 and $: Go to the beginning and end of the line.
  • gg and G: Go to the very top and very bottom of the buffer.
  • y: Yank (copy) the current line.
  • v: Start visual mode (select character by character).
  • V: Start visual line mode (select line by line).
  • y (after selection): Yank the selected text.
  • q: Quit copy mode.

Emacs Mode:

  • Up and Down arrows: Move up and down lines.
  • Left and Right arrows: Move left and right characters.
  • M-f (Alt+f) and M-b (Alt+b): Move forward and backward by words.
  • Ctrl+a and Ctrl+e: Go to the beginning and end of the line.
  • M-< (Alt+<) and M-> (Alt+>): Go to the very top and very bottom of the buffer.
  • M-w: Yank (copy) the current line.
  • Ctrl+v: Start visual mode (select character by character).
  • Shift+v: Start visual line mode (select line by line).
  • M-w (after selection): Yank the selected text.
  • Ctrl+c: Quit copy mode.

To copy the command apt update && apt upgrade -y:

  1. Enter copy mode (Ctrl+b [ for Vi, Ctrl+b Ctrl+[ for Emacs).
  2. Navigate your cursor to the beginning of the line containing the command.
  3. Press v (Vi) or Ctrl+v (Emacs) to enter visual mode.
  4. Move your cursor to the end of the command. You’ll see the text highlighting as you move.
  5. Press y (Vi) or M-w (Emacs) to yank (copy) the selected text into tmux’s buffer.
  6. Press q (Vi) or Ctrl+c (Emacs) to exit copy mode.

Now, to paste it back into the same or a different tmux pane, you’d use your prefix followed by ]. So, Ctrl+b ].

The system that makes this work is tmux’s internal buffer, often referred to as the "paste buffer" or "copy buffer." When you yank text in copy mode, it’s stored in this buffer. When you paste, tmux retrieves it from there. This buffer is session-specific, meaning the content persists as long as the tmux session is running but is lost when the session ends.

The key to understanding this is that tmux doesn’t just capture screen output; it maintains a scrollback buffer for each pane. Copy mode allows you to interact with this buffer directly, treating it as a navigable text document. The Vi and Emacs bindings are simply mappings to commands that manipulate a cursor within this buffer and select/yank text.

The distinction between Vi and Emacs key bindings is a configuration choice. By default, tmux uses Vi bindings. You can change this globally in your ~/.tmux.conf file:

# Use Emacs key bindings for copy mode
setw -g mode-keys emacs

Or for Vi (which is the default, so this is usually unnecessary unless you’ve changed it):

# Use Vi key bindings for copy mode
setw -g mode-keys vi

Reload your tmux configuration by pressing Ctrl+b : then typing source-file ~/.tmux.conf and pressing Enter.

A detail that trips many people up is the difference between tmux’s paste buffer and the system clipboard. When you yank text in tmux, it goes into tmux’s buffer. If you want to paste that text into an application outside of tmux (like a web browser or another terminal window not managed by tmux), you need to use a specific integration. This is often handled by plugins like tmux-yank or by configuring tmux to interact with the system clipboard using set-clipboard on. Without this, Ctrl+b ] only pastes into other tmux panes or windows within the same session.

Once you’ve mastered copy mode, the next logical step is to look into tmux’s scripting capabilities, specifically using command-prompt and run-shell to automate actions based on buffer content.

Want structured learning?

Take the full Tmux course →