Hello to all you command-line enthusiasts out there! I’m sure many of you, just like me, love the simplicity and efficiency of using vi (or vim) for text editing. The intuitive keyboard shortcuts, the speed – it’s just unbeatable! Now, what if we could bring that experience into Tmux? Well, that’s exactly what we’re going to do today. We’re going to enable vi-like or vim-like copy-paste in Tmux, making our command line experience that much more seamless. So let’s dive right in and get started!
Just starting out with Tmux? Don’t miss out on the Tmux basics. Seasoned with Tmux? Let’s take the plunge!
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 vim-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 vim-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 vim-like copy pasting functionality in tmux was useful. And voila! We’ve just infused the power and simplicity of vim-like copy-pasting into Tmux. This tweak, while small, can make a world of difference in your efficiency and ease of use. I, for one, couldn’t imagine going back to the old way of doing things. I hope you find this change as helpful as I do. Remember, it’s these little customizations that make the command line such a powerful tool. So keep exploring, keep learning, and above all, keep coding!
You can also check out the complete tmux cheatsheet of keyboard shortcuts and mouse shortcuts.