【发布时间】:2014-11-16 13:01:00
【问题描述】:
如何在 Vim 的 netrw 中执行 grep? ctrl-p可以这样用,有没有类似grep的插件?
例如,当我在一个目录中时,我想要一个包含 this 或 that 关键字的文件列表。
【问题讨论】:
如何在 Vim 的 netrw 中执行 grep? ctrl-p可以这样用,有没有类似grep的插件?
例如,当我在一个目录中时,我想要一个包含 this 或 that 关键字的文件列表。
【问题讨论】:
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>进入文件。
【讨论】:
Netrw 没有这个功能。
你可以使用内置的:vimgrep:
:vim foo * | cw
或:grep,默认使用您的外部grep 或通过grepprg 选项使用任何替代程序(如ack 或ag):
:grep foo * | cw
请参阅:help :grep、:help :vimgrep 和 :help :cwindow。
【讨论】:
let netrw_keepdir = 0 使 netrw 的浏览目录和 Vim 的当前目录保持同步。您也可以将其保留为默认值并按c。见:help netrw-c。
:vimgrep 搜索目录,例如::vim foo dir/* 并递归地像::vim foo dir/**。我还建议您查看 Ack、Ag the Silver Surfer 或 git grep,因为它们通常比常规 grep 性能更高,当然:vimgrep