Mastodon hachyterm.io

Today I learned how to paste into Vim in insert mode (and normal mode).

When I write my blog posts, I often have to refer to material from the internet: other articles, blog posts, or books.

That means that I will have to copy the title and URL from the web and paste it into my Vim editor.

First of all, the "* and "+ registers are for the system clipboard.

If you are in normal mode, you can paste with "+p or "*p.

You can add some clever settings to your .vimrc:

nnoremap <leader>rr "+diwP"

That key-binding will replace the word under the cursor with the system clipboard. It will first delete the current word (iw) and then put (paste) the stuff inside the clipboard before the current cursor (+P).

Now, how can you paste code from the clipboard without leaving insert mode?

That’s where <CTRL+R> (or in Vim-speak: <C-R>) comes into place. Use <C-R>+ to paste from the + register.

Further Reading