Grep/Ack 带括号和分号的表达式

Grep/Ack expression with parenthese and semicolon

我正在使用来自 Silver Searcher 的 vim Ag.vim。我想在我的项目中搜索 let(:application

如果我这样做 :Ag "let(:application" app/ 我得到

|| ERR: Bad regex! pcre_compile() failed at position 16: missing )
|| If you meant to search for a literal string, run ag with -Q

Ag -Q "let(:application" app/

没有结果

知道正确的模式吗?

您可以转义 (:

Ag 'let\(:application' app/

或将 grep-F 一起用于固定字符串:

grep -F "let(:application" app/

估计你被vim的magic模式和ag的模式弄糊涂了:

传递给 ag 的正则表达式模式参数 遵循您的 vim 的 magic 设置。默认情况下 ag 应用 PCRE 所以你必须转义 (ag 知道你想要匹配 literal (。或者您提供 -Q 选项来实现相同的目标。