Jesse Leite
Jesse Leite

Reputation: 8031

How do I ag search into a specific set of folders using the -G option?

How do I ag search into a specific set of folders using the -G option?

Here's an example where I use -G routes, but it's picking up another result from another folder, because routes is still in the path. Yet if I try -G ^routes, it doesn't seem like the regex is taking?

enter image description here

On that note, Atom has a nice path searching syntax which lets me do things like app,routes,!storage (search in app and routes folders, but ignore storage folder). Since I've switched to vim, I'm finding it hard to get a searching workflow down with ack/ag. Anyone have any tips for me?

Upvotes: 2

Views: 4424

Answers (1)

sudavid4
sudavid4

Reputation: 1141

I suppose you'd really like to try this plugin https://github.com/junegunn/fzf.vim. It will (among other things) run your ag search and present the result in a fuzzyfinder. Then you'll have the very same feature you mention in atom by running :Ag middleware followed by(in the fzf window) 'app/ 'routes/ !storage/'.

about the use of regex for the file pattern, you'll need to quote your regex

ag -G '^routes' middleware

that being said, the '^...' doesn't work as intended here on my computer either, although '\b' does. I started using ripgrep instead of the-silver-searcher not so much because it's faster but rather because it has a better documentation, maybe you'd like to give it a try. rg -g will take a glob which is easier to understand than the "FILEPATTERN" mentioned in the ag man page

Upvotes: 2

Related Questions