- OP wanted to populate quickfix list with buffers that DON'T match pattern given to
- I suggested that
'grepprg' could be used if
- 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
:set grepprg=grep\ -L
: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.
'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)