how to call vim on files that are the results of a grep -l command in bash?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

how to call vim on files that are the results of a grep -l command in bash?

DwigtArmyOfChampions
From a bash shell I can type "grep -l 'foo' *" and that will output a list of files that contain 'foo'. I want to vim that list of files. In other words, assuming the grep command returns file1, file2, ... filen, I want to run the command:

vim file1 file2 file3 ... filen

I tried "grep -l 'foo' * | vim" and "grep -l 'foo' * | xargs | vim' but those didn't work. Any ideas?

--
--
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/7d6607c5-2a07-4556-830c-a546045d317b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Legacy Email] how to call vim on files that are the results of a grep -l command in bash?

Reid Thompson-2
On Fri, 2019-05-24 at 04:40 -0700, DwigtArmyOfChampions wrote:

> [EXTERNAL SOURCE]
>
>
>
> From a bash shell I can type "grep -l 'foo' *" and that will output a list of files that contain 'foo'. I want to vim that list of files. In other words, assuming the grep command returns file1,
> file2, ... filen, I want to run the command:
>
> vim file1 file2 file3 ... filen
>
> I tried "grep -l 'foo' * | vim" and "grep -l 'foo' * | xargs | vim' but those didn't work. Any ideas?
>
> --


vim $(grep -l foo)


--
--
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/910a7cf2180c990a7d8eb6e09a4b5fa5879d5856.camel%40omnicell.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Legacy Email] how to call vim on files that are the results of a grep -l command in bash?

Reid Thompson-2
On Fri, 2019-05-24 at 07:50 -0400, Reid Thompson wrote:

> On Fri, 2019-05-24 at 04:40 -0700, DwigtArmyOfChampions wrote:
> > [EXTERNAL SOURCE]
> >
> >
> >
> > From a bash shell I can type "grep -l 'foo' *" and that will output a list of files that contain 'foo'. I want to vim that list of files. In other words, assuming the grep command returns file1,
> > file2, ... filen, I want to run the command:
> >
> > vim file1 file2 file3 ... filen
> >
> > I tried "grep -l 'foo' * | vim" and "grep -l 'foo' * | xargs | vim' but those didn't work. Any ideas?
> >
> > --
>
> vim $(grep -l foo)
>

this is the xargs one


ls ycm* | xargs vim

--
--
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/ddbd50ad42431a60e0ec6cf5500a37ae3bfdd831.camel%40omnicell.com.
For more options, visit https://groups.google.com/d/optout.
Kit
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

Kit
In reply to this post by DwigtArmyOfChampions
grep -l 'foo' * | xargs vim
--
Kit

2019-05-24 13:40 GMT+02:00, DwigtArmyOfChampions > I tried "grep -l
'foo' * | vim" and "grep -l 'foo' * | xargs | vim' but
> those didn't work. Any ideas?

--
--
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/CAAVKVq-TH-Ffu8dXE6znDFJ3V2%2BXvG8dNZJaHGpXLQaFRDf9jQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

arocker
> grep -l 'foo' * | xargs vim
> --

Or, if the number isn't likely huge:

vim $(grep -l 'foo' *)

--
--
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/9f19e9106278ed4fbddd02b423bcd4d9.squirrel%40webmail.vybenetworks.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

Tim Chase
In reply to this post by DwigtArmyOfChampions
On 2019-05-24 04:40, DwigtArmyOfChampions wrote:
> From a bash shell I can type "grep -l 'foo' *" and that will output
> a list of files that contain 'foo'. I want to vim that list of
> files. In other words, assuming the grep command returns file1,
> file2, ... filen, I want to run the command:
>
> vim file1 file2 file3 ... filen

As others have mentioned, you have

 vim $(grep -l 'foo' *)

and

 grep -l foo * | xargs vim

(which then has vim complain that input isn't from stdin)

Moreover, vim has some built-in grepping functionality which might be
helpful:

  :vimgrep foo *

then you can use

  :cn
  :cN
  :crew

to navigate them, as well as (at least as of a somewhat recent
version of vim) the

  :cdo
  :cfdo

commands which let you perform operations across all the matches or
across all the matching files.  Especially since :vimgrep supports all
the power of Vim's regular expressions which can do things that
grep(1) can't do.

-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/20190524083202.4c3ea784%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

Gary Johnson-4
In reply to this post by DwigtArmyOfChampions
On 2019-05-24, DwigtArmyOfChampions wrote:
> From a bash shell I can type "grep -l 'foo' *" and that will
> output a list of files that contain 'foo'. I want to vim that list
> of files. In other words, assuming the grep command returns file1,
> file2, ... filen, I want to run the command:
>
> vim file1 file2 file3 ... filen
>
> I tried "grep -l 'foo' * | vim" and "grep -l 'foo' * | xargs | vim'
> but those didn't work. Any ideas?

Using xargs with an interactive program like vim has problems, such
as leaving your terminal in an odd state after vim exits.  A better
solution is to use GNU parallel:

    $ grep -l 'foo' * | parallel --tty -X vim

Regards,
Gary

--
--
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/20190524152145.GA24449%40phoenix.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

Tony Mechelynck
Another possibility is to tell Vim that the file to be read will be
found on stdin:

       grep -l 'foo' | view -

One problem with this approach is that using "view" (because stdin is
essentially non-writable) will make ":new foobar" open the new file
read-only as if you had used :sview rather than :new. IIUC in order to
make the new file writable you will have to use ":setl noro" after
making it current.

Best regards,
Tony.

--
--
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/CAJkCKXsJ2QSjuQRBH1_Jjr--Eg_GdAQNHq9fLEWJr9D7znZFGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: how to call vim on files that are the results of a grep -l command in bash?

Paul-7
In reply to this post by DwigtArmyOfChampions
On Fri, May 24, 2019 at 04:40:54AM -0700, DwigtArmyOfChampions wrote:
>From a bash shell I can type "grep -l 'foo' *" and that will output a list of files that contain 'foo'. I want to vim that list of files. In other words, assuming the grep command returns file1, file2, ... filen, I want to run the command:
>
>vim file1 file2 file3 ... filen
>
>I tried "grep -l 'foo' * | vim" and "grep -l 'foo' * | xargs | vim' but those didn't work. Any ideas?

I use the quickfix list for this. Previous commands will break on whitespace in filepaths. This won't (but it will on newlines - I didn't figure out how to work it with Vim for those), but you'll have to tell your command to use a null as a separator, eg. `grep -Zl foo * | pvim`:

pvim() {
    local files=()
    while IFS= read -rd '' file; do
        files+=("$file")
    done
    (( ${#files[@]} )) && vim -q <( printf '%s:1: \n' "${files[@]}" ) < /dev/tty
}

--
--
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/20190526110331.GA24963%40rainslide.net.
For more options, visit https://groups.google.com/d/optout.

signature.asc (817 bytes) Download Attachment