使用vim编辑器复制所选文本n次

时间:2016-12-10 13:15:51

标签: vim copy-paste

如何复制多行并粘贴它们' n'使用vi编辑器的次数。

例如:

This is the first line.
This is the second line.
This is the third line.

现在我想复制3行,因为它们是一个接一个地100次,如:

#First copy
This is the first line.
This is the second line.
This is the third line.
#Second copy
This is the first line.
This is the second line.
This is the third line.
...
...

2 个答案:

答案 0 :(得分:1)

假设您要复制这三个连续的行:

This is the first line.
This is the second line.
This is the third line.

然后将它们粘贴在三对三:

This is the first line.
This is the second line.
This is the third line.
This is the first line.
This is the second line.
This is the third line.
This is the first line.
This is the second line.
This is the third line.
...

并且你的光标在第一行,你可以通过混合使用Ex命令和普通模式命令来实现你的目标:

3:y<CR>jj99p

扩展为:

:.,.+2y<CR>jj99p

或像这样用视线选择:

Vjjy99p

或者像这样,如果您知道行号:

:1,3y|3|normal! 99p<CR>

或者像这样,如果你想使用&#34;段落&#34;文本对象和动作:

yip}99p

或简单地说:

3yjj99p

我相信你还能找到更多的方法。

答案 1 :(得分:1)

Vim有一个名为 count 的概念,它有助于迭代很多命令。

在这种情况下,yanking和pasting可以与count一起使用。

3 y 将抽出3行。
1 0 0 p 会将这些行粘贴100次。

运行:h count了解详情

  

可以在命令之前的可选数字乘以
  或迭代命令。如果没有给出数字,则计数为一   除非另有说明,否则使用。