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.
Asked
Active
Viewed 5.1k times
4 Answers
75
yank those lines in register:
:364,757yEnter
if you want to copy those lines and paste to some certain line, t is your friend. for example:
:364,757t2Enter will copy those lines to under 2nd line.
if you want to copy them to right under your current line:
:364,757t.Enter
Kent
- 189,393
- 32
- 233
- 301
-
3Great examples, precisely the next thing I wanted to learn :) – Smooth Operator Jan 15 '14 at 16:12
-
2The t command `:t` that Kent mentions is an alias for `:copy` -- documented here: http://vimdoc.sourceforge.net/htmldoc/change.html#:copy – Purplejacket Aug 29 '16 at 20:14
-
5Thank you. It's worth to mention that if you want to move instead of copy, change `t` with `m` – Hoang Tran Jun 03 '17 at 10:54
-
Is it possible to do it with relative numbers of lines? – Stanislaw Baranski Jun 19 '19 at 19:47
-
2@StanislawBaranski yes, `.+3` is 3 lines below the cursor – Kent Jun 20 '19 at 09:03
-
@Kent But how about the source range. e.g. :.+10,+5t. doesn't work. – Stanislaw Baranski Jun 22 '19 at 14:54
-
2@StanislawBaranski it works here. In the example you gave a backwards range. try `.+5, .+10t.` – Kent Jun 24 '19 at 08:35
-
I need about a month to do nothing but study `vi` commands. I think it'd be worth the investment. – Matt Cremeens Dec 02 '22 at 11:32
61
: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.
William Pursell
- 204,365
- 48
- 270
- 300
7
You can yank (copy in vim terms) from line 364 to line 757 by typing
:364,757y<enter>
ThanksForAllTheFish
- 7,101
- 5
- 35
- 54