[英]How to copy specific number of lines more in a file?
I would like to copy n
more number of lines in a file. 我想在文件中复制n
多行。 At the moment, I am doing this indirectly: From current line x
, I use V<x+n>ggy
where <x+n>
is substituted with the actual sum. 此刻,我正在间接执行此操作:从当前行x
,我使用V<x+n>ggy
,其中<x+n>
被替换为实际的总和。
Is there a way to copy directly n
more lines from current line? 有没有办法从当前行直接复制n
行呢?
You don't need to go into visual mode (the V
) for that. 您不需要为此进入可视模式( V
)。 The normal mode yy
command already takes a [count]
, but that includes the current line. 普通模式yy
命令已经有一个[count]
,但是包括当前行。 So for n more lines , you need to pass a [count]
of n + 1. Example: Yank current and 2 more lines (total 3): 3yy
. 因此,对于另外n行 ,您需要传递[count]
为n +1。例如:抽出当前行和另外2行(共3行): 3yy
。
If you don't want to do the arithmetic, you can also use the :yank
Ex command. 如果您不想进行算术运算,也可以使用:yank
Ex命令。 The range there is specified as you want: current ( .
) until current plus n ( .+n
). 根据需要指定该范围:current( .
)直到current加n( .+n
)。 Example: :.,.+2yank
例如:: :.,.+2yank
Based on your preference to visual mode, and using gg
instead of G
to move to a line, it appears as if you're still new to Vim. 根据您对视觉模式的偏爱,并使用gg
而不是G
移至一行,看起来好像您还是Vim的新手。 Learn how to look up commands and navigate the built-in :help
; 了解如何查找命令并浏览内置的:help
; it is comprehensive and offers many tips. 它是全面的,并提供了许多技巧。 You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor. 学习Vim的速度不会像其他编辑器那样快,但是如果您坚持不懈地学习,它将证明它是一个功能强大且高效的编辑器。
Okay, I found the solution myself while playing around. 好吧,我在游戏时自己找到了解决方案。 n
more lines can be simply copied by using: Vn+y
使用以下命令可以简单地复制n
行: Vn+y
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.