Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: How to yank a visual block to a register?

Tags:

I can yank a line to register a by "ayy.

But I am not able to figure out a way to yank some visually selected block to a particular register. If I just press y after selection, it stores it in the default register. But I need to store it in a specific register, how can this be achieved?

like image 952
prat0318 Avatar asked Feb 18 '14 09:02

prat0318


People also ask

How do I yank a block in vim?

You can copy a block of text by pressing Ctrl-v (or Ctrl-q if you use Ctrl-v for paste), then moving the cursor to select, and pressing y to yank. Now you can move elsewhere and press p to paste the text after the cursor (or P to paste before).

How do I change a block of text in Vim?

One may overwrite a visual-block of text with another visual-block of text by: Select the first block: ctrl-v move "ay. Select the second block: ctrl-v move c ctrl-o "aP <Esc>


Video Answer


2 Answers

It's the same behaviour, but you tell the register after the visual selection.

An example:

You select some text in visual mode and copy it to register a:

V4j"ay

Go to end of file:

G

And paste it:

"ap
like image 104
Birei Avatar answered Oct 13 '22 00:10

Birei


I can select a block using shift+v or vap (read: "visually select around paragraph") and then yank it using "ay. When I want to paste it again I use "ap or "aP.

Does this work for you?

like image 28
Flo Avatar answered Oct 13 '22 00:10

Flo