Robert Webb wrote:
> Hi,
> 
> In a vim script, what's the best way to load a file (to search for
> some info), then get rid of it again without any side-effects.
> Eg, it shouldn't change the alternative buffer, it should no longer
> be loaded in a hidden buffer, and it should work even when there's not
> enough room to split the window.
> 
> I could split to a new tab, then load the file into it, then do :bdel.
> But would this cause tab-flashing as the GUI is changed, or is there a
> way to prevent the update?  And would this be an inefficient way to do
> it?
> 
> I could also use readfile(), which would probably suffice, but is this
> more or less efficient than loading a file into a vim buffer.  I will
> still need to read the whole file either way since I don't know how
> far through the file I will need to look.
> 
> Now if there was a searchfile() function, that would be handy :-)
> Eg, pass it a file name and a pattern to search for, and maybe the
> maximum number of matches, and a list of matching lines is returned.
> That way if the match is found early and you only ask for one, then
> vim wouldn't bother reading the rest of the file.

There is the :vimgrep command, the getqflist() etc. functions, and the
:colder command, with which you could perhaps cobble something together.
It doesn't have the nice optimisation of searching for a single match
that you'd like, but it does avoid adding and removing buffers and so
on. Or possibly you could use :grep--does external grep have an option
to exit after a certain number of matches? Maybe.

So it still might not be what you want, but it's something else to throw
in the mix to investigate!

Ben.



--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui