Use vi keys in copy mode
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:
hjkl- 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.
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-selectionPress 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.
Here is what just happened.
The two set lines redirected copy mode and the prompt to the vi tables. The bind -T copy-mode-vi line added v to that table, and since mode-keys is now vi, that is the table copy mode consulted. Enter ran copy-selection-and-cancel, the vi table’s equivalent of M-w.
- Use the copy-mode-vi key table in copy mode and vi keys at the prompt:set -g mode-keys vi
- Rebind a copy mode key by sending a copy mode command with -X:bind -T copy-mode-vi v send -X begin-selection
- Copy the selection and leave copy mode (vi table; h j k l move, 0 and $ go to line ends)Enter
Go further
VISUAL=viorEDITOR=viin the shell before the server starts sets both options with no file.tmux lsk -T copy-mode-vilists the whole vi table; compare with-T copy-mode.man tmuxlists every-Xcommand, including unbound ones likecopy-pipe.
- 1Editing the file changes nothing until you source it:
C-b :thensource ~/.tmux.conf. - 2Three lines:
set -g mode-keys vi,set -g status-keys vi,bind -T copy-mode-vi v send -X begin-selection. - 3With vi keys,
kmoves up,0to line start,$to line end. On the deploy line:0,v,$, Enter.
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
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- The window option mode-keys is set to vi— not done yet
- The session option status-keys is set to vi— not done yet
- v in the copy-mode-vi table is bound to begin-selection— not done yet
- The most recent paste buffer holds the deploy key line— not done yet