Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim -- How to read range of lines from a file into current buffer

Tags:

vim

I want to read line n1->n2 from file foo.c into the current buffer.

I tried: 147,227r /path/to/foo/foo.c

But I get: "E16: Invalid range", though I am certain that foo.c contains more than 1000 lines.

like image 383
Aman Jain Avatar asked Oct 27 '08 15:10

Aman Jain


People also ask

How do I select a range of lines in Vim?

Press V to switch to VISUAL LINE mode and then go to line 1701 by typing: 1701G . Now your lines are selected, you can run a command on them. For example, to replace foo with bar type: :s/foo/bar/ .

How do I find the current file name and number of lines in Vim?

Pressing ctrl-g will reveal the filename, current line, the line count, your current position as a percentage, and your cursor's current column number.

What Vim command allows you to move to the first line in the current file?

Press ^ to move the cursor to the start of the current line. Press $ to move the cursor to the end of the current line.


1 Answers

:r! sed -n 147,227p /path/to/foo/foo.c 
like image 81
boxxar Avatar answered Oct 10 '22 17:10

boxxar