On 14:31 Wed 21 Mar , Taylor Hedberg wrote:
> Roman Dobosz, Wed 2012-03-21 @ 18:53:29+0100:
> > Is it possible to vimgrep all opened buffers, not just the current
> > one?
>
> Well, :vimgrep really operates on files, not buffers. The `%` in the
> command I gave previously expands to the filename of the current buffer.
This is not exactly right: if there is a buffer vimgrep makes the search in
the buffer not in the file (written on the disc) which might differ from what
is in the buffer (if it is modified).
> You can replace that with a list of files (or a glob pattern, like
> `*.c`) to search over multiple files at once.
>
> I don't know of any easy way to grep over all open buffers, but you
> could probably come up with a function that does it. Something to this
> effect would probably work (tested, but only a little bit):
>
> function! GrepOpenBuffers(pattern)
> let bufnames = ''
> for i in filter(range(1, bufnr('$')), 'bufexists(v:val)')
> let bufnames .= ' ' . bufname(i)
> endfor
> execute 'vimgrep /' . a:pattern . '/ ' . bufnames
> endfunction
> command! -nargs=1 GrepOpenBuffers call GrepOpenBuffers(<args>)
You should use vimgrepadd as I poseted (and clear the quickfix list :call
setqflist([])).
>
> Then use the defined command to do the search:
>
> :GrepOpenBuffers 'some search pattern'
>
> Maybe there's a simpler way to do this that I'm overlooking. Hopefully
> someone else will show me up. :)
You can also use lvimgrepadd and setloclist() instead of vimgrep and
setqflist() and use :llist instead of :clist. This is helpfull if you use
quickfix for compilation errors for example.
Best,
Marcin
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php