On Mon, Oct 27, 2008 at 10:09 AM, Tim Chase wrote: > > John Beckett wrote: >> Aman Jain wrote: >>> I want to read line n1->n2 from file foo.c into current buffer >>> I tried :147,227r /path/to/foo/foo.c >> >> The ':read' command reads a whole file into the current buffer, below the >> specified >> range (after line 227 in the current buffer). >> >> You could use some external tool which reads the wanted lines and outputs >> them to >> stdout (see ':help :r!'). > > Just to have it in the thread, if you've got sed in your path > (available on all *nix boxes): > > :r! sed -n '147,227p' > > This also works nicely if it's a humongous file that would bring > Vim to its knees, but you only want a known slice, sed streams > the file so it may take a while, but it won't kill your system/vim.
The fact that sed needs to read the the file up until it hits the lines you're interested in can't be helped, but you can have it quit after the last line that you want printed. That will help significantly if you only want a few lines near the beginning of a very large file, something like: :r! sed -n '147,227p;228q' file ~Matt --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
