i want to yank multiple lines in a single register in vim, to easily paste different text templates in a document.

for example, "iyy yanks only the the current line, if i try to select multiple lines in visual-mode, it isn't written into the register.

any suggestions?

link|improve this question
"if i try to select multiple lines in visual-mode, it isn't written into the register." <-- Really? Works for me... – Billy ONeal Jan 17 '11 at 16:28
and for me too... – ulidtko Jan 17 '11 at 16:32
ah ok, i've tried with "iyv, silly me. should be Vjjj"iy like ulidtko mentioned. – ryz Jan 17 '11 at 17:03
feedback

3 Answers

up vote 6 down vote accepted

Use 3Y to yank 3 lines into the default register; "i3Y for yanking into register i.

Also, my favorite way is not to count the lines I want to yank, but to select them in visual mode via V and moving commands, and then hit y to yank it or "_y to yank into a register.

Also, I have just tried selecting multiple lines in Visual Line mode and yanking into not-default register, e.g. Vjjj"oy — and it works.

link|improve this answer
+1 - but V is Visual Line Mode, v is visual mode. – Billy ONeal Jan 17 '11 at 16:27
ok, ok, right. Visual Line Mode. %) – ulidtko Jan 17 '11 at 16:31
thanks, totally works! – ryz Jan 17 '11 at 17:04
@ryz accept the answer if it was useful – ulidtko Jan 17 '11 at 17:07
gladly accepted it, fastest way for me yet. – ryz Jan 17 '11 at 17:12
feedback

Use m to mark the start, with a buffer name (so you might type mx). Move your cursor down to where you want to stop copying, and type y'x (or d'x if you're cutting and pasting). Then move the to the point where you want to paste, and type p.

The Vim command cheat sheet

link|improve this answer
Are you sure you don't mean v not m? – Billy ONeal Jan 17 '11 at 16:27
feedback

You prefix the command with a number to get how many lines to operate on. You could also use a 'text-object' (like ']' for block, and ')' for paragraph) - this would work on multiple lines contextually - the default is often a single line. For example, "r5yy would yank five lines starting at the cursor into the 'r' register. (Or you could type :.,+4y r to do the same in ex mode.) You can combine numbers with text-objects as well; "r10y).

link|improve this answer
thanks, works. thank you very much! – ryz Jan 17 '11 at 17:05
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.