How to Copy Multiple Lines and Sections of Text with Vim
I'm making this page from scratch in Vim. Because why not. To make this happen there are several strings of text that I want to copy to different places. I want the page title to go in
<title> in the
<head> element, in
<h1>, and in links to the page, like in index. The url needs to go in sitemap.xml and also obviously in links to the page.
Named registers make this whole process awesome. It's kind of like having multiple clipboards. Actually, that's almost exactly what it's like. So I wrote the page title down, then selected it with v, 1, 0, e, e, then ", t, y yanks (copies) the text to a register named t -- t for title. Now I can paste from this register with ", t, p or append to it with ", shift + T, y. Doing ", t, y will overwrite the t register.
Copy and paste works like usual, just with the ", u or whatever letter preamble to specify the register name. So, for instance, copy a whole line to the t register with ", t, y, y. Paste the line below the cursor with ", t, p, or above the cursor with ", t, P.
This works well between documents. I just updated my sitemap using the u register -- u for url. Where this does not work is between two instances of Vim running at the same time in two different windows. Which is a bummer. But there's a way around this, which I will write about, soon.