Vim: How to Copy to Your System Clipboard
Share
Interests
Posted in these interests:
If you find yourself highlighting text in Vim with your mouse to copy and paste it elsewhere, stop. There’s a better way, using the yank command, to copy text into your clipboard on macOS or Windows.
TL;DR
"*y
Use the yank command
You may be familiar with the yank
command: y
to copy selected text, yy
to copy the current line. To copy to the system clipboard, we’ll use the same command with a few extras modifier to select the correct register.
Choosing a register
In Vim, you choose a register using "
.
The system register
For both Mac and Windows, you can select the system register by using *
.
Putting it all together
Enter visual mode by hitting v
. Select the text you want to copy, then type:
"*y
Now go paste freely!