tags:

views:

1241

answers:

3

Hi

I want to read line n1->n2 from file foo.c into 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.

Thanks

Aman Jain

A: 

The {range} refers to the destination in the current file, not the range of lines in the source file.

After some experimentation, it seems

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

means insert the contents of /path/to/foo/foo.c after line 227 in this file. i.e.: it ignores the 147.

Stewart Johnson
+6  A: 
:r! sed -n 147,227p /path/to/foo/foo.c
boxxar
A: 

You will need to:

:r /path/to/foo/foo.c

:d 228,$

:d 1,146

Three steps, but it will get it done...

PaulB
this is so much typing , sorry :)
Aman Jain
Not a good solution - not compared with the sed solution.
Jonathan Leffler