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

前端 未结 7 1922
梦毁少年i
梦毁少年i 2021-01-30 03:49

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

7条回答
  •  执笔经年
    2021-01-30 04:37

    I just had to do this in a code project of mine and did it this way:

    In buffer with /path/to/foo/foo.c open:

    :147,227w export.txt
    

    In buffer I'm working with:

    :r export.txt
    

    Much easier in my book... It requires having both files open, but if I'm importing a set of lines, I usually have them both open anyway. This method is more general and easier to remember for me, especially if I'm trying to export/import a trickier set of lines using g/> export.txt or some other more complicated way of selecting lines.

提交回复
热议问题