本文介绍了如何在整个项目/文件夹中递归搜索一个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我正在搜索一个文件夹内的类 JFactory ,它是子目录。



我将那个包含 class JFactory



的文件归档,我不想替换那个词,但是我需要找到包含 class JFactory 的文件。

解决方案

:vimgrep / JFactory / ** / *。java

/ JFactory / / \< JFactory \> / 如果您想要全字匹配。 :vim 的缩写:vimgrep



JFactory \< JFactory \> 是您当前的搜索模式(例如,你可以使用一个空的搜索模式::vimgrep // ** / *。java ,它会改用最后的搜索模式。方便!

警告::vimgrep 会触发autocmds(如果启用)。这可能会减慢搜索速度。如果你不想这样做:

 :noautocmd vimgrep / \< JFactory \> / * * / *。java 

这会更快。但是:它不会触发语法高亮显示或者打开 gz 文件未压缩等。



请注意,如果你想一个外部程序来grep你的模式,你可以做如下的事情:

 :set grepprg = ack 
:grep --java JFactory

Ack 是一个Perl替代grep。请注意,您将不得不切换到Perl正则表达式。



一旦您选择的命令返回,您可以使用Vim文档中描述的命令浏览搜索结果在:help quickfix 。查找:cfirst :cnext :cprevious :cnfile 等等。

2014更新:现在有新的方法可以用 the_silver_searcher the_platinum_searcher ag.vim 联合。 vim 插件。


Suppose I'm searching a class JFactory inside a folder and it's sub-directories.

How can I file that file which contains class JFactory?

I don't want to replace that word but I need to find that file that contains class JFactory.

解决方案
:vimgrep /JFactory/ **/*.java

You can replace the pattern /JFactory/ with /\<JFactory\>/ if you want full word match. :vim is shorthand for :vimgrep.

If JFactory or \<JFactory\> is your current search pattern (for example you have hit * on one occurrence) you can use an empty search pattern: :vimgrep // **/*.java, it will use last search pattern instead. Handy!

Warning: :vimgrep will trigger autocmds if enabled. This can slow down the search. If you don't want that you can do:

:noautocmd vimgrep /\<JFactory\>/ **/*.java

which will be quicker. But: it won't trigger syntax highlighting or open gz files ungzipped, etc.

Note that if you want an external program to grep your pattern you can do something like the following:

:set grepprg=ack
:grep --java JFactory

Ack is a Perl-written alternative to grep. Note that then, you will have to switch to Perl regexes.

Once the command of your choice returned, you can browse the search results with those commands described in the Vim documentation at :help quickfix. Lookup :cfirst, :cnext, :cprevious, :cnfile, etc.

2014 update: there are now new ways to do that with the_silver_searcher or the_platinum_searcher and either ag.vim or unite.vim plugins.

这篇关于如何在整个项目/文件夹中递归搜索一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:31