learntmux.dev

Use vi keys in copy mode

Goal

mode-keys and status-keys are vi, v starts a selection, and the deploy key line is copied.

Copy mode keys live in two tables — copy-mode (emacs) and copy-mode-vi — and the mode-keys option picks which one is consulted. set -g mode-keys vi switches to the vi table:

h j k l
move
0 / $
start and end of the line
/ and ?
search forward and back
Enter
copy and leave

status-keys vi does the same for the command prompt.

One rebind is worth making: in the vi table v is rectangle-toggle by default, and Space begins a selection. bind -T copy-mode-vi v send -X begin-selection gives v the meaning it has in vi. Copy mode commands are always sent with send-keys -X, so any binding in either table reads send -X command.

Do this

Run open ~/.tmux.conf, add these lines, and save with Ctrl-S:

set -g mode-keys vi
set -g status-keys vi
bind -T copy-mode-vi v send -X begin-selection

Press C-b :, type source ~/.tmux.conf, Enter.

Editing the file alone changed nothing; this is what applies it.

Press C-b [, then k until the cursor is on deploy key: deploy-key-7f3a9c2e, then 0.

The cursor sits at the start of the line.

Press v, then $, then Enter.

The line highlights, then copy mode ends with the line in a buffer.

The default copy-mode tables

Both tables default to emacs — unless VISUAL or EDITOR contained vi when the server started, in which case tmux picks vi for you.

Stuck on this one?

This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.

A real terminal, in this tab

about 15 MB, once

session learn

Done when

not started
  1. The window option mode-keys is set to vi— not done yet
  2. The session option status-keys is set to vi— not done yet
  3. v in the copy-mode-vi table is bound to begin-selection— not done yet
  4. The most recent paste buffer holds the deploy key line— not done yet