Skip to main content
Bumped by Community user
Bumped by Community user
Made examples more generic.
Source Link

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs"txt" | xargs grep -l "fs::""some text" 

I can then quickly review the files output by find in vim:

vim -p `find . -type f -name "*.rs"txt" | xargs grep -l "fs::"`"some text"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs"txt" -print0 | xargs -0 grep -l "fs::""some text" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vim -p `find . -type f -name "*.rs"txt" -print0 | xargs -0 grep -l "fs::"`"some text"` 

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs" | xargs grep -l "fs::" 

I can then quickly review the files output by find in vim:

vim -p `find . -type f -name "*.rs" | xargs grep -l "fs::"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vim -p `find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::"` 

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.txt" | xargs grep -l "some text" 

I can then quickly review the files output by find in vim:

vim -p `find . -type f -name "*.txt" | xargs grep -l "some text"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.txt" -print0 | xargs -0 grep -l "some text" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vim -p `find . -type f -name "*.txt" -print0 | xargs -0 grep -l "some text"` 
added 2 characters in body
Source Link
romainl
  • 45.7k
  • 5
  • 91
  • 129

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs" | xargs grep -l "fs::" 

I can then quickly review the files output by find in vim:

vivim -p `find . -type f -name "*.rs" | xargs grep -l "fs::"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vivim -p `find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::"` 

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs" | xargs grep -l "fs::" 

I can then quickly review the files output by find in vim:

vi -p `find . -type f -name "*.rs" | xargs grep -l "fs::"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vi -p `find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::"` 

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs" | xargs grep -l "fs::" 

I can then quickly review the files output by find in vim:

vim -p `find . -type f -name "*.rs" | xargs grep -l "fs::"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vim -p `find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::"` 
Source Link

Opening Vim tab pages via find/xargs with paths including spaces

I often open multiple files in vim using tab pages:

$ vim --help | grep tab -p[N] Open N tab pages (default: one for each file) 

I also use find with xargs and grep -l to obtain a list of files.

find . -type f -name "*.rs" | xargs grep -l "fs::" 

I can then quickly review the files output by find in vim:

vi -p `find . -type f -name "*.rs" | xargs grep -l "fs::"` 

The earlier grep command would fail if there are spaces in the files or directories, so -print0 can be added to the arguments to find; and -0 can be added to the arguments to xargs:

find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::" 

But if I then try to pass the output of this command to vim tab pages (as below), the paths including spaces are split, and opened as non-existent files. Is there a way to get past the problem?

vi -p `find . -type f -name "*.rs" -print0 | xargs -0 grep -l "fs::"`