Using vimgrep to find files NOT containing a string

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Using vimgrep to find files NOT containing a string

russurquhart1
Hi All,

I generally use:

:vim `beta: ` **/*.md | copen

To traverse my Markdown files to find those containing 'beta: '.

I need to do the opposite but can get the pattern right. I tried

:vim -v `beta: ` **/*.md | copen

thinking that might work but no dice.

I looked through teh vimgrep help but couldn't find anything.

Does anyone know how to do this?

Thank you, 

Russ

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1293083986.1897663.1599074077407%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using vimgrep to find files NOT containing a string

Marius Gedminas
On Wed, Sep 02, 2020 at 07:14:37PM +0000, russurquhart1 via vim_use wrote:

> I generally use:
>
> :vim `beta: ` **/*.md | copen
>
> To traverse my Markdown files to find those containing 'beta: '.
>
> I need to do the opposite but can get the pattern right. I tried
>
> :vim -v `beta: ` **/*.md | copen
>
> thinking that might work but no dice.
>
> I looked through teh vimgrep help but couldn't find anything.
>
> Does anyone know how to do this?

Not with vimgrep, but on the command line to find files that don't
contain a pattern I generally do

  grep -c "beta: " **/*.md | grep ':0$' | sed -e 's/:0$//'

this assumes your shell can do ** and it's probably not the most
elegant/efficient way of doing it, but it's one that I can remember how
to spell.

And then I opened the grep manual page to see if there's an easier way,
and lo and behold:

       -L, --files-without-match
              Suppress normal output; instead print the name of each
              input file from which no output would normally have  been
              printed.  The scanning will stop on the first match.

Just what the doctor ordered!

To feed these files to to vim you could play with temporarily setting
'grepprg', or use :args `grep -L "beta: " **/*.md`

If your shell doesn't do **, you may need to use something a bit more
complicated like

   find -name '*.md' -exec grep -L "beta: " {} +

HTH,
Marius Gedminas
--
Si hoc legere scis nimium eruditionis habes.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200903070704.trx46k7456rjuhhj%40blynas.
Reply | Threaded
Open this post in threaded view
|

Re: Using vimgrep to find files NOT containing a string

Tim Chase
In reply to this post by russurquhart1
On 2020-09-02 19:14, russurquhart1 via vim_use wrote:

> Hi All,
> I generally use:
> :vim `beta: ` **/*.md | copen
> To traverse my Markdown files to find those containing 'beta: '.
> I need to do the opposite but can get the pattern right. I tried
> :vim -v `beta: ` **/*.md | copen
>
> thinking that might work but no dice.
> I looked through teh vimgrep help but couldn't find anything.
> Does anyone know how to do this?

While I don't know off the top of my head how to coerce :vim to do
this, I'd likely populate the arglist with everything

  :args **/*.md

and then either wipe the buffers you don't want:

  :argdo g/beta:/bwipe

or remove them from the arg list

  :argdo g/beta:/argd %

depending on which you prefer.

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200903072316.377c37f0%40bigbox.attlocal.net.
Reply | Threaded
Open this post in threaded view
|

Re: Using vimgrep to find files NOT containing a string

russurquhart1
In reply to this post by Marius Gedminas
Thank you for the reply! I will give this a shot!

This has been a big help!!

Russ


-----Original Message-----
From: Marius Gedminas <[hidden email]>
To: [hidden email] <[hidden email]>
Sent: Thu, Sep 3, 2020 2:07 am
Subject: Re: Using vimgrep to find files NOT containing a string

On Wed, Sep 02, 2020 at 07:14:37PM +0000, russurquhart1 via vim_use wrote:

> I generally use:
>
> :vim `beta: ` **/*.md | copen
>
> To traverse my Markdown files to find those containing 'beta: '.
>
> I need to do the opposite but can get the pattern right. I tried
>
> :vim -v `beta: ` **/*.md | copen
>
> thinking that might work but no dice.
>
> I looked through teh vimgrep help but couldn't find anything.
>
> Does anyone know how to do this?

Not with vimgrep, but on the command line to find files that don't
contain a pattern I generally do

  grep -c "beta: " **/*.md | grep ':0$' | sed -e 's/:0$//'

this assumes your shell can do ** and it's probably not the most
elegant/efficient way of doing it, but it's one that I can remember how
to spell.

And then I opened the grep manual page to see if there's an easier way,
and lo and behold:

      -L, --files-without-match
              Suppress normal output; instead print the name of each
              input file from which no output would normally have  been
              printed.  The scanning will stop on the first match.

Just what the doctor ordered!

To feed these files to to vim you could play with temporarily setting
'grepprg', or use :args `grep -L "beta: " **/*.md`

If your shell doesn't do **, you may need to use something a bit more
complicated like

  find -name '*.md' -exec grep -L "beta: " {} +

HTH,
Marius Gedminas
--
Si hoc legere scis nimium eruditionis habes.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+[hidden email]
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200903070704.trx46k7456rjuhhj%40blynas.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/1299755177.202881.1599138996832%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using vimgrep to find files NOT containing a string

russurquhart1
In reply to this post by Tim Chase
Thanks Tim, I'll look at this! All this info helps!!

Thanks again!

Russ


-----Original Message-----
From: Tim Chase <[hidden email]>
To: russurquhart1 via vim_use <[hidden email]>
Sent: Thu, Sep 3, 2020 7:23 am
Subject: Re: Using vimgrep to find files NOT containing a string

On 2020-09-02 19:14, russurquhart1 via vim_use wrote:

> Hi All,
> I generally use:
> :vim `beta: ` **/*.md | copen
> To traverse my Markdown files to find those containing 'beta: '.
> I need to do the opposite but can get the pattern right. I tried
> :vim -v `beta: ` **/*.md | copen
>
> thinking that might work but no dice.
> I looked through teh vimgrep help but couldn't find anything.
> Does anyone know how to do this?

While I don't know off the top of my head how to coerce :vim to do
this, I'd likely populate the arglist with everything

  :args **/*.md

and then either wipe the buffers you don't want:

  :argdo g/beta:/bwipe

or remove them from the arg list

  :argdo g/beta:/argd %

depending on which you prefer.

-tim


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+[hidden email]
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200903072316.377c37f0%40bigbox.attlocal.net.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/982441949.2253819.1599144317943%40mail.yahoo.com.
Reply | Threaded
Open this post in threaded view
|

Re: Using vimgrep to find files NOT containing a string

Bram Moolenaar
In reply to this post by Marius Gedminas

Marius Gedminas wrote:

> On Wed, Sep 02, 2020 at 07:14:37PM +0000, russurquhart1 via vim_use wrote:
> > I generally use:
> >
> > :vim `beta: ` **/*.md | copen
> >
> > To traverse my Markdown files to find those containing 'beta: '.
> >
> > I need to do the opposite but can get the pattern right. I tried
> >
> > :vim -v `beta: ` **/*.md | copen
> >
> > thinking that might work but no dice.
> >
> > I looked through teh vimgrep help but couldn't find anything.
> >
> > Does anyone know how to do this?
>
> Not with vimgrep, but on the command line to find files that don't
> contain a pattern I generally do
>
>   grep -c "beta: " **/*.md | grep ':0$' | sed -e 's/:0$//'
>
> this assumes your shell can do ** and it's probably not the most
> elegant/efficient way of doing it, but it's one that I can remember how
> to spell.
>
> And then I opened the grep manual page to see if there's an easier way,
> and lo and behold:
>
>        -L, --files-without-match
>               Suppress normal output; instead print the name of each
>               input file from which no output would normally have  been
>               printed.  The scanning will stop on the first match.
>
> Just what the doctor ordered!

Not exactly.  This switches from reporting matches to reporting file
names with matches.  The output won't be parsed properly.

> To feed these files to to vim you could play with temporarily setting
> 'grepprg', or use :args `grep -L "beta: " **/*.md`
>
> If your shell doesn't do **, you may need to use something a bit more
> complicated like
>
>    find -name '*.md' -exec grep -L "beta: " {} +

The grep program has a long list of options, I don't think we will
want to add them all to :vimgrep.  Especially if it's about listing
files with/without matches, there are several other ways to do that.

--
You know you use Vim too much when you have this alias in your
~/.bashrc file: alias :e=/bin/vim             (Eljay Love-Jensen)

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/202009031450.083Eolqu060864%40masaka.moolenaar.net.