Grep for String and open at the corresponding line

前端 未结 3 1288
死守一世寂寞
死守一世寂寞 2021-01-21 05:58

I\'m having several occurrences of a specific string over several files in several lines obtained with grep.

$ grep -rn --include=\"*.cpp\" mystring         


        
相关标签:
3条回答
  • 2021-01-21 06:28

    Here is another way to do

    $ grep -rn --include="*.cpp" mystring > op
    $ vim op
    

    Then use gF and to come back to file op, use Ctrl + 6

    0 讨论(0)
  • 2021-01-21 06:31

    You can load your grep output in Vim's quickfix list with:

    $ vim -q <(grep -rn --include="*.cpp" mystring)
    

    Go to the next occurence with :cn and to the previous occurrence with :cp.

    See :help -q and :help quickfix.

    0 讨论(0)
  • 2021-01-21 06:34

    A trick to use vim as a pager is to pass it a hyphen character. This causes it to read from STDIN instead of from file

    grep -rn --include="*.cpp" mystring | vim -
    
    0 讨论(0)
提交回复
热议问题