2016-12-10 32 views
0

如何複製多行並使用vi編輯器將其粘貼'n'次。使用vim編輯器複製選定的文本n次

例如:

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

現在我想,他們是一前一後像100倍,3線複製:

#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. 
... 
... 
+0

我試圖格式化您的問題,但我不確定您的實際目標。你可以使用適當的減價重新格式化它嗎? – romainl

+1

您可以在'p'之前使用動作。使用'3y'和'100p'粘貼3行' –

+0

正是我在尋找幾個小時。我試圖用「yy」來抽出,它只能複製指定的行。謝謝!! –

回答

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> 

或類似這樣的,如果你想使用「段落」文本對象和運動:

yip}99p 

或者乾脆:

3yjj99p 

我相信你可以找到更多的方法。

+0

'99P'而不是'jj99p'? – FDinoff

+0

@FDinoff,是的,這是我在這種情況下會做的。 – romainl

1

Vim有一個概念叫做count,它有助於迭代大量的命令。

在這種情況下,yanking和pasteing可以與count一起使用。

y將抽出3行。
p將粘貼這些行的100倍。

運行:h count瞭解更多

可以在命令前乘
或重複命令一個可選的數字。如果沒有給出號碼,除非另有說明,否則使用一個
的計數。