Copy to macOS clipboard in vim visual mode

I always had trouble finding a way to copy lines of code in vim when I wanted to paste the lines in some other application on macOS. You see vim doesn’t use the OS clipboard when it copies something.

I finally found a way:

echo "vmap '' :w !pbcopy<CR><CR>" >> ~/.vimrc

Now, whenever you select visual mode using :v, select some text, and press '' the text will be copied to the macOS clipboard.

It may not be the best solution as it depends on having pbcopy installed on your system, and it does a weird flicker, but it works!

Now, you may ask why I am using vim? That’s another question, maybe for another post. 😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s