DEV Community

Waylon Walker
Waylon Walker

Posted on • Originally published at

ag silver searcher look ahead and look behind

A super useful tool when doing PR's or checking your own work during a big refactor is the silver searcher. Its a super fast command line based searching tool. You just run ag "<search term>" to search for your search term. This will list out every line of every file in any directory under your current working directory that contains a match.


It's often useful to need some extra context around the change. I recently reviewed a bunch of PR's that moved schema from save_args to the root of the dataset in all yaml configs. To ensure they all made it to the top level DataSet configuraion, and not underneath save_args. I can do a search for all the schemas, and ensure that none of them are under save_args anymore.

ag "schema: " -A 12 -B 12
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

moopet profile image
Ben Sinclair

These are flags copied from grep and they'll also work in other replacements like ack and ripgrep.

waylonwalker profile image
Waylon Walker

Oh nice, not sure why I didn't put this together in the moment. I always forget them and have to look them up in the --help. I just looked in my history and saw that I have used it with rg many times.