47

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.

Mika H.
  • 4,119
  • 11
  • 44
  • 60

4 Answers4

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
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
8

Not sure if my answer is needed

but you can yank one line number by

:123y

Harman Nieves
  • 151
  • 1
  • 2
  • 8
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