- Published on
Enable vi-like copy paste in Tmux
Tmux is one of the most useful tool when it comes to using a linux terminal.
Tmux is a terminal multiplexer, it allows a user to access multiple terminals (or windows), each running a separate program, while providing a single screen to work on. Tmux is useful for running more than one command-line program at the same time, increasing productivity and the way you work.
To enable vi/vim like copy-paste on Tmux
You can bind a few keys to make the experience of copy-paste work like vi/vim like. So, you can select, copy and paste using vi-style. To make this happen, we will add the following lines of code to ~/.tmux.conf
-
set-window-option -g mode-keys vi
bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi y send-keys -X copy-selection
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
After adding the above line to the configuration file, you can reload tmux conf-
tmux source-file ~/.tmux.conf
Now, you can attach to any tmux session, and then run the list-keys
command. The list-keys
command will list everything related to vi
/vim
-like functionality available to you in the vi-mode configuration that you did earlier.
By default the prefix is Ctrl-B
, let's consider that and continue with the commands.
Ctrl-B
:list-keys -T copy-mode-vi
Copying text using vi-mode in tmux
Once the above ~/.tmux.conf
is configured in tmux, you can enter the vi-like copy mode using the following keyboard shortcuts-
Ctrl-B + [
You can leave or exit from the copy mode by pressing the ENTER
key. You can continue the selection by pressing SPACE
on the characters, and then press ENTER
key to complete. You can also use q
to quit from the vi-mode.
Pasting text using vi-mode in tmux
Once you have copied text as you see above, you can paste the text in any window or pane in that session by using the following keyboard shortcuts-
Ctrl-B + ]
Alternatively, you can also enable mouse gives you options to clipboard and copy-paste from tmux window and Windows or Linux or MAC Clipboard. This will enable copy-paste and mouse behaviour on tmux.
I hope this tutorial for enabling vi-like copy pasting functionality in tmux was useful. You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.