Vim复制一行并将其粘贴到多行 [英] Vim copy one line and paste it to multiple lines

查看:1829
本文介绍了Vim复制一行并将其粘贴到多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确定我知道该怎么做,但是我尝试了其他机器,但似乎不知道.

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

这样就变成了

1 COPY THIS
2
3
4 COPY THIS
5 COPY THIS

我尝试的方法:在第1行上按Shift-V以可视模式复制行,然后在第4行和第5行转到第4行可视模式垂直选择.现在,p粘贴.

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.

会发生什么:将其粘贴到第4行,然后删除第5行.

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

我可以在这里寻求友好的帮助吗?

May I ask a friendly help here?

推荐答案

您必须粘贴两次:2p而不是p

You must paste twice: 2p instead of p

此外,如果您只想整行复制一条线,则可以跳过视线并仅使用yy

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

并完全消除视觉模式:

:0
yy
:4
2dd
2"0p

这将做到:

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.

另请参见在Unix上的此问题与解答. SE

这篇关于Vim复制一行并将其粘贴到多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆