Vim copy one line and paste it to multiple lines [closed]

孤者浪人 提交于 2020-01-06 14:17:15

问题


I was sure I knew how to do it but I tried on different machines and it seems I don't know.

1 COPY THIS
2
3
4 HERE
5 HERE

So that it becomes

1 COPY THIS
2
3
4 COPY THIS
5 COPY THIS

What I tried: Shift-V on line 1 to copy line in visual mode, then go to line 4 visual mode vertical selection on lines 4 and 5. Now p to paste.

I was expecting to paste to both lines.

What happens: It paste to line 4 and line 5 gets deleted.

May I ask a friendly help here?


回答1:


You must paste twice: 2p instead of p

also, if you only want to copy one line whole, you can skip the visual line and just use yy

and to eradicate the visualmode altogether do this:

:0
yy
:4
2dd
2"0p

which will do:

GOTO line 0
copy the current line
GOTO line 4
delete the following two lines (*)
twice: paste line from register 0

(*) note that the deletion overrides the entry in the default register.

See also this Q&A on Unix.SE



来源:https://stackoverflow.com/questions/52016333/vim-copy-one-line-and-paste-it-to-multiple-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!