To open files in Grep's output to Vim's -o -mode

Viewed 22004

How can you put a list of files to Vim's -o -mode?

I have a list of files as Grep's output. I run unsuccessfully

1

grep -il sid * | vim -o

2

grep -il sid * | xargs vim -o

3

grep -il sid * | xargs vim

4

vim -o `grep -il sid *`

5

vim -o | grep -il sid *
6 Answers

To invoke vim using xargs, xargs must be invoked with -o:

grep -il sid * | xargs -o vim -o

In case filenames could contain spaces, use grep -Z with xargs -0

grep -ilZ sid * | xargs -0 -o vim -o

Without xargs -o, we would get a warning:

Vim: Warning: Input is not from a terminal

The -o option exists on OSX/BSD. Also, the -o option is found in GNU findutils built from git. This option was added after 4.6.0.

Related