4

I try to search for {% amount in all files under the current directory.

Using ag, this works fine:

ag -Q '{% amount'

(-Q specify to not use any regex, try to match text literally)

I have this in my .vimrc:

grepprg=ag --nogroup --nocolor --column

And when I use :grep -Q '{% amount' I get the following error:

E499: Empty file name for '%' or '#', only works with ":p:h"

Which (in my understanding) mean that Vim try to expand % and fail (because I've not opened any file).

My question is: How to search for a litteral % when using external grep program?


Note: thanks to statox I know that the following works:

:vimgrep /%/ *
  • 4
    escape the '%' using '\', e.g. use '\%' – Christian Brabandt Oct 14 '16 at 13:37
  • 1
    Thanks, cannot believe it this simple! If you want to make that an answer, I'll happily accept it. – nobe4 Oct 14 '16 at 13:39
4

In the Vim command line, the % is a special placeholder for the current buffer name. See :help cmdline-special. To avoid the expansion, just escape the character with a backslash: :grep -Q '{\% amount'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.