Fork me on GitHub

When I do "search project" (SPC /), type some pattern (or just press SPC * at the beginning), then I would like to filter the results only coming from certain subdirectory - like SPC s f but specifying the directory only after the search pattern. Is there an easy way to achieve that?


If using ripgrep (and probably silver-searcher) exclude a file or directory with the -g!directory-name option at the start of the search prompt For example, to search for uses of the pattern token but avoid searching in a directory called customer-token within a project tree, I would use SPC / to start the project search and type -g!customer-token token . This will list all the files that have the pattern token except for files inside the customer-token directory.


Thanks, John, a really good answer. I'm in fact interested in including a directory, not excluding it. But it's very similar to what you said - I just need to specify a proper glob like this -gmy-dir-name/** search-pattern


Ah yes the /** is needed when including a specific directory and removing the ! of course -gcompany-token/** token from my earlier suggestion. I think the /** is supposed to be used when excluding a directory too, although it seemed to work without okay.