Vim: How to Copy to Your System Clipboard

John John (304)
2 minutes

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.


Posted in these interests:
h/vim23 guides

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:


Now go paste freely!

John John (304)
5 minutes

So you've started using Kubernetes secrets. At some point, you'll probably want to see the secret in plain text, either to validate it or use it in another context.