Vim tip: excluding files and paths from searches with Grepper

Grepper is a plugin for Vim to search your project asynchronously using your preferred search tool. By default Grepper will search Vim’s current directory and its subdirectories, in many projects that I work on this includes things I generally do not want to search in (with directories container vendor libraries such as node_modules).

You can pass extra options for the tool of your choice to the Grepper commands, ripgrep (which is what I use) supports a glob argument which you can use to exclude paths (and files) like so:

:GrepperRg --glob '!vendor' --glob '!node_modules' --glob '!public' --glob '!test/vcr_cassettes' 'Hello Word'

To prevent yourself from typing a ton of globs each time you want to search you can add a command to your vimrc for common combinations like so:

command! -nargs=+ -complete=file Search :GrepperRg --glob '!vendor' --glob '!node_modules' --glob '!public' --glob '!doc'

The above snippet adds a Search command to vim which excludes paths I generally do not want to search within in Rails projects which you can use like so:

:Search 'Hello World'