To recap:
- OP wanted to populate quickfix list with buffers that DON'T match pattern given to
:vimgrep
.
- I suggested that
'grepprg'
could be used if :vimgrep
couldn't.
- OP revised requirements based on better understanding of quickfix: wants to DELETE those same buffers.
- OP found a solution for the IS matching case and quickfix:
:vimgrep /exp/ ## | cfdo argdelete % | bdelete
- ...but didn't think the inverse could be done analogously.
In fact, my original suggestion is still valid even with the new goal. This is how you can do it with command-line grep and 'grepprg'
:
:set grepprg=grep\ -L
:set grepformat=%f
:grep PATTERN ##
:cfdo argdelete % | bdelete
The key things here are to
- Specify command line grep with the flag (
-L
) that returns names of files that DO NOT include the given pattern.
- Change
'grepformat'
to account for grep only returning filename (%f
) and not line numbers.
The rest is nearly identical to the is matching case except we use :grep
instead of :vimgrep
and we don't surround the pattern with delimiters (e.g. //
).
I did a quick test with six buffers loaded, four of which contained text matching my pattern of choice. Ran all of the above and was left with just the other two buffers.
Update: Some feedback from @raylight (OP):
Since I work a lot with snippets on shortcuts I've adapted it for one line like
:set grepprg=grep\ -L | set grepformat=%f | grep 'expression' ## | cfdo argd % | bd
The expression seems to work better when it's around single quotes for some reason too (I've tested with a word containing ` and it didn't work without the single quotes)
'grepprg'
with external (shell-based) grep might get you where you want to go.grep -v
show the lines that do not match the pattern... Trygrep -L
for the files that don't have any lines matching the pattern. (Not sure if that's enough to populate the quick fix list with it using:grep
command, but maybe try that and see how far it takes you.)'grepprg'
and'grepformat'
right. I'll add an answer shortly