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?


V20Gy, if I understand your question correctly.

  • You definitely do, thanks. Simple and visualized way Oct 5 '16 at 17:28
  • 3
    This is a good approach, but visual mode is unnecessary. Since G is a linewise motion, you could simply do y20G
    – DJMcMayhem
    Oct 5 '16 at 18:59
  • @DJMcMayhem, probably then with :set rnu even better to use relative movements with y20j? 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.
    – aring
    Oct 5 '16 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.