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.
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>)
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. :)
pgp3q4dorsr5E.pgp
Description: PGP signature
