Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to copy by specifying line numbers in vi

Tags:

vim

vi

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.

like image 379
Mika H. Avatar asked Feb 25 '13 14:02

Mika H.


People also ask

How do I copy line numbers in vi?

Press the ESC key to be sure you are in vi Command mode. Place the cursor on the first line of the text you wish to copy. Type 12yy to copy the 12 lines. Move the cursor to the place where you wish to insert the copied lines.

How do I go to a specific line number in vi editor?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.


2 Answers

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

like image 75
Kent Avatar answered Sep 23 '22 21:09

Kent


:364,757y should work just fine, but it is probably more common to just do something like 364GV757Gy

like image 44
William Pursell Avatar answered Sep 19 '22 21:09

William Pursell