The trouble with:
:vimgrep // ./**/*.py
is that it will search for the last search pattern, that's what //
does, so you can basically get two unsatisfactory outcomes:
- there is nothing in register
/
, therefore you get an error,
- there is something in register
/
, therefore you possibly get a quickfixlist, with possibly one entry for possibly every desired file.
That is a pretty haphazard strategy.
One way to make it more deterministic while keeping it lo-tech would be to use a more precise pattern that is sure to be found exactly once, in every single matching file:
:vimgrep /\%1l/ **/*.py
where we search for line 1, which is guaranteed to be found even in empty files.
See :help \%l
.
Another lo-tech approach could be to do something like:
set efm=%f
:cexpr glob('**/*.py')
set efm&
where we:
- temporarily change the
:help 'errorformat'
option so that it can deal with a list of files,
- use
:help :cexpr
to populate the quickfix list with the output of :help glob()
, parsed according to the errorformat
option,
- revert
errorformat
to its default value.
But that assumes that errorformat
was the default value to begin with.
One could also probably do something similar with $ man find
or $ man locate
. Or possibly with a combination of :help setqflist()
and glob()
, etc.
But I think the \%1l
trick is the easiest to pull "on the spot": just basic vimming without any setup or third-party cruft.
