Updated May 2017 to show the new syntax for the copy-mode keys.
tmux offers a set of vi-like bindings for navigating a buffer in a window. These allow you to not only navigate through the buffer beyond what your screen is currently showing, but also to search all the output generated thus far, and to select and copy text that can be pasted in any other window in the tmux session.
You can enable this as a default setting in
.tmux.conf with the following:
set-window-option -g mode-keys vi
You can confirm this is working by pressing Ctrl+B and then : in a tmux session to bring up the command line, and typing:
list-keys -T copy-mode-vi
In version 2.3 and below, the syntax is different:
list-keys -t vi-copy
This will bring up a complete list of the vi-like functionality available to you in this mode.
With this done, within a tmux instance, pressing Ctrl+B and then
[ will enter
copy mode, allowing you to copy text or view the history of the buffer,
including searching with
?. Most of the basic vi movements work,
including screenwise vertical movement commands like Ctrl+F and Ctrl+B. You can
leave this mode just by pressing Enter, or you can start a selection by
pressing Space on a character, moving to another, and then pressing Enter. If
you have text copied like this you can paste it into any tmux window in that
session by pressing Ctrl+B and then
If you don’t mind artifically introducing a few Vim-only features to the vi
mode, you can set things up so that
v starts a selection and
y finishes it
in the same way that Space and Enter do, more like Vim:
bind-key -T copy-mode-vi 'v' send -X begin-selection bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel
In version 2.3 and below, the syntax is very different:
bind-key -t vi-copy 'v' begin-selection bind-key -t vi-copy 'y' copy-selection
Even if you’re using a terminal emulator in a GUI environment, if you get good at using this you’ll find it’s much faster and more precise than clicking and dragging to select text to copy and paste it. It keeps you from having to move to the mouse, and additionally eliminates the problem of copying whole lines split into more than one panes.
Note that all of the above assumes that your prefix is the default of Ctrl+B, which many tmux users, myself included, seem to prefer to change to the old GNU Screen prefix key of Ctrl+A.