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 [email protected].
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.

Attachment: signature.asc
Description: PGP signature

Reply via email to