How can I search for queries including %, $ and the likes? I tried to prefix then with '\', enclosing in quotes, but it only makes it worse:

:Ag "$r"
|| ERR: Error: No query. What do you want to search for?

:Ag "\$r"
No matches for ""\$r""

:Ag \\$r
|| ERR: Bad regex! pcre_compile() failed at position 1: \ at end of pattern
|| If you meant to search for a literal string, run ag with -Q

:Ag -Q "\\$r"
:Ag -Q \\$r
No Error, but finds god knows what

:Ag "\%whatever"
|| ERR: Error: No query. What do you want to search for?

:Ag "%whatever"
E499: Empty file name for '%' or '#', only works with ":p:h"
  • What happens if you use single quotes? – VanLaser Sep 10 '15 at 9:02

Did you try the following?

:Ag \\$
| improve this answer | |
  • I have updated the question with more examples including this one. – firedev Sep 10 '15 at 7:26
  • @firedev Try :Ag \\\$. '\\' to escape '\' and '\$' to escape $. :Ag '\$' (with single quotes) also works if you don't want a ton of slashes. EDIT: Ugh, same stuff here.... – tokoyami Sep 10 '15 at 12:09
  • For %. That requires double slashes inside single quotes and four outside: :Ag '\\%' or :Ag \\\\%. – tokoyami Sep 10 '15 at 12:27

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.