How to Copy Multiple Lines and Sections of Text with Vim

By Christopher Kielty, updated Jan 11, 2019
tweet share email rss

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 v10ee, then "ty yanks (copies) the text to a register named t -- t for title. Now I can paste from this register with "tp or append to it with "shift + Ty. Doing "ty 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 "tyy. Paste the line below the cursor with "tp, or above the cursor with "tP.

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.


tweet share email rss