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.
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.
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.
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
:364,757y
should work just fine, but it is probably more common to just do something like 364GV757Gy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With