Suppose I am on line 10
, and I want to yank to line 20
. Usually I will do 10y
. Sometimes I do the subtraction wrong, and copy the wrong number of lines. Is there a way to copy directly from current line to line 20
without doing the subtraction?
2 Answers
V20Gy
, if I understand your question correctly.
-
You definitely do, thanks. Simple and visualized way Commented Oct 5, 2016 at 17:28
-
3This is a good approach, but visual mode is unnecessary. Since
G
is a linewise motion, you could simply doy20G
Commented Oct 5, 2016 at 18:59 -
@DJMcMayhem, probably then with
:set rnu
even better to use relative movements withy20j
? Less keystrokes (there is no shift needed), and there will be rarely more than two digits, meanwhile - in absolute mode line numbers can easily exceed four-digit and even more.– aringCommented Oct 5, 2016 at 20:34
The :[range]y[ank] [x]
command allows specifying the range through the normal cmdline range syntax.
In your example, you could use :.,20y
to yank from the current line through line 20 into the default register or :.,20y a
to yank into register a
.