Vim copy a block and paste it to multiple lines

2019-07-29 11:43发布

I know I can yyon line 1 and then visual select lines 4 and 5 2p(Vim copy one line and paste it to multiple lines).

1 COPY THIS
2
3
4 HERE
5 HERE

So I get:

1 COPY THIS
2
3
4 COPY THIS
5 COPY THIS

But instead, let's say I would like just COPY. If I visual block select COPY and then 2p on lines 4 and 5 visual selected

1 COPY THIS
2
3
4 COPYCOPY
5 

How do I paste 1x at each line? Like:

1 COPY THIS
2
3
4 COPY
5 COPY

1条回答
姐就是有狂的资本
2楼-- · 2019-07-29 11:54

You can modify the register " (unnamed) to contain a newline, but at this point its most likely easier to create a new line, paste your content in it and dd it again.

v
l (or other moving chars to mark the area you want)
y
:let @" = @" . "\n"
2p

For further ideas see also this thread.

查看更多
登录 后发表回答