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

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.


:r! sed -n 147,227p /path/to/foo/foo.c

You can do it in pure Vimscript, without having to use an external tool like sed:

:put =readfile('/path/to/foo/foo.c')[146:226]

Note that we must decrement one from the line numbers because arrays start from 0 while line numbers start from 1.

Disadvantages: This solution is 7 characters longer than the accepted answer. It will temporarily read the entire file into memory, which could be a concern if that file is huge.