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

前端 未结 6 983
死守一世寂寞
死守一世寂寞 2021-01-31 14:19

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          


        
相关标签:
6条回答
  • 2021-01-31 14:52

    The second one should work unless some of those filenames contain whitespace. You should do

    grep -il sid * | xargs -d "\n" vim -o
    

    if this is a possibility. -d "\n" tells xargs to use a newline as the delimiter when reading in the arguments; normally it is any whitespace (newline, tab, or space character)

    0 讨论(0)
  • 2021-01-31 14:53

    Sorry I'm late. Some of these options work for me but with weird side effects. Try this:

    vim -o $(grep -il sid *)
    
    0 讨论(0)
  • 2021-01-31 14:56

    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.

    0 讨论(0)
  • 2021-01-31 15:03

    Try

    vim -p `grep -il sid *`
    

    if you want to open the files in different tabs in the same window.

    0 讨论(0)
  • 2021-01-31 15:03

    Run:

    grep -il sid * | vim -
    

    This tell vim to read the file from stdin, so the output of grep will be in vim. Now, put cursor on file and press gF - this will open the file on the line grep indicated.

    You can also use ^WF to open file in a new split.

    0 讨论(0)
  • 2021-01-31 15:17

    Second one works for me. Third too, although you get only one file visible at the start. 4 is the same as 2 in most cases. First and last should not work by design.

    0 讨论(0)
提交回复
热议问题