:vimgrep
looks like a really useful thing.
Here's how to use it:
:vim[grep][!] /{pattern}/[g][j] {file} ...
:help
says that you can essentially glob {file}
to name, say, *.c
for the current directory. I may have started Vim with a list of files that is complicated enough that I don't want to manually type it in for {file}
, and besides Vim already knows what those files are.
What I would like to do is vimgrep over any of:
:args
:files
:buffers
What variable(s) would I use in place of {file}
to name, respectively, any of those lists in a vimgrep
command?
Can't you catch the result in these commands into a register (:h :redir
), and insert it back into :vimgrep
call (with a :exe
).
Something like:
:exe "vimgrep/pattern/ " . lh#askvim#Exe(':args')
Notes:
:redir
; nothing really complex:args
that adds square brackets)join(argv(), ' ')
in :args
case.
function BuffersList()
let all = range(0, bufnr('$'))
let res = []
for b in all
if buflisted(b)
call add(res, bufname(b))
endif
endfor
return res
endfunction
:exe 'vimgrep/pattern/ '.join(BuffersList(),' ')