【问题标题】:How do I grep in vim netrw?我如何在 vim netrw 中 grep?
【发布时间】:2014-11-16 13:01:00
【问题描述】:

如何在 Vim 的 netrw 中执行 grep? ctrl-p可以这样用,有没有类似grep的插件?

例如,当我在一个目录中时,我想要一个包含 this 或 that 关键字的文件列表。

【问题讨论】:

    标签: vim grep netrw


    【解决方案1】:

    Netrw 确实有“那个特性”;请参阅 :help netrw-star。例如,您可以使用 :Explore */filepat 或更一般地使用以下模式之一:

    */filepat   files in current directory which satisfy filepat
    **/filepat  files in current directory or below which satisfy the
                file pattern
    *//pattern  files in the current directory which contain the
                pattern (vimgrep is used)
    **//pattern files in the current directory or below which contain
                the pattern (vimgrep is used)
    

    使用:Pexplore:Nexplore 转到上一个/下一个匹配文件(和@: 重复选择的命令);点击<cr>进入文件。

    【讨论】:

      【解决方案2】:

      Netrw 没有这个功能。

      你可以使用内置的:vimgrep

      :vim foo * | cw
      

      :grep,默认使用您的外部grep 或通过grepprg 选项使用任何替代程序(如ackag):

      :grep foo * | cw
      

      请参阅:help :grep:help :vimgrep:help :cwindow

      【讨论】:

      • 不会在我的密码而不是我所在的 netrw 目录中搜索吗?
      • let netrw_keepdir = 0 使 netrw 的浏览目录和 Vim 的当前目录保持同步。您也可以将其保留为默认值并按c。见:help netrw-c
      • 您可以使用:vimgrep 搜索目录,例如::vim foo dir/* 并递归地像::vim foo dir/**。我还建议您查看 AckAg the Silver Surfergit grep,因为它们通常比常规 grep 性能更高,当然:vimgrep
      猜你喜欢
      • 1970-01-01
      • 2014-03-08
      • 2014-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多