vimgrep是VIM寻找模式匹配的内部方法,可以自动识别换行符和编码,并且
可以使用VIM强大的正则表达式。缺点是相对慢些,因为所有文件都要读
入内存。
语法
:vim[grep][!] /{pattern}/[g][j] {file} …
Search for {pattern} in the files {file} … and set
the error list to the matches.
Without the ‘g’ flag each line is added only once.
With ‘g’ every match is added.
{pattern} is a Vim search pattern. Instead of
enclosing it in / any non-ID character (see
|’isident’|) can be used, so long as it does not
appear in {pattern}.
‘ignorecase’ applies. To overrule it put |/c| in the
pattern to ignore case or |/C| to match case.
‘smartcase’ is not used.
When a number is put before the command this is used
as the maximum number of matches to find. Use
":1vimgrep pattern file" to find only the first.
Useful if you only want to check if there is a match
and quit quickly when it’s found.
Without the ‘j’ flag Vim jumps to the first match.
With ‘j’ only the quickfix list is updated.
With the [!] any changes in the current buffer are
abandoned.
来个简单的例子
在 d:mydocs下查找含有“弹冠相庆”的txt文档,但不跳到第一个匹配
:vimgrep /弹冠相庆/gj d:/mydocs/*/*.txt
如果要包含子文件夹,则用
:vimgrep /弹冠相庆/gj d:/mydocs/**/*.txt
打开quickfix窗口查看匹配结果
:cw
参考资料:
http://vimcdoc.sourceforge.net/doc/quickfix.html
:h vimgrep
大清早写文章,厉害!
赞赞