How can I copy by specifying line numbers in vi, e.g. lines 364-757? I tried searching for this but cannot find such a command.
4 Answers
yank those lines in register:
:364,757y
Enter
if you want to copy those lines and paste to some certain line, t
is your friend. for example:
:364,757t2
Enter will copy those lines to under 2nd line.
if you want to copy them to right under your current line:
:364,757t.
Enter
-
3Great examples, precisely the next thing I wanted to learn :) Jan 15, 2014 at 16:12
-
2The t command
:t
that Kent mentions is an alias for:copy
-- documented here: vimdoc.sourceforge.net/htmldoc/change.html#:copy Aug 29, 2016 at 20:14 -
5Thank you. It's worth to mention that if you want to move instead of copy, change
t
withm
Jun 3, 2017 at 10:54 -
2
-
2@StanislawBaranski it works here. In the example you gave a backwards range. try
.+5, .+10t.
– KentJun 24, 2019 at 8:35
:364,757y
should work just fine, but it is probably more common to just do something like
364GV757Gy
, allowing the range to be interactively modified when you realize that you really means line 759 or so.
You can yank (copy in vim terms) from line 364 to line 757 by typing
:364,757y<enter>