Exclude files from searches in Visual Studio Code

For several years now I’ve been using Visual Studio Code as my main editor, and one bugbear of mine was that by default a search in a project would find results in all the third party libraries. Most of the time this isn’t what I want, as I’m mainly concerned with the code I’ve written.

My requirements for excluding files were:

  • Permanent exclusion: Whilst you can specify excluded files as part of a search, I didn’t want to have to do this each time.
  • Shared exclusion: I wanted the exclusions to be placed in version control, so that anyone with a copy of the repository would be using the same settings (if they’re using VSCode, which is my recommendation for developers who haven’t chosen an IDE and don’t want to pay for PHPStorm).

Fortunately, VSCode stores most of its per-project settings in a plain text file at the following location (relative to the project root):

.vscode/settings.json

Anything under the search.exclude section won’t be shown in search results. For example, to exclude anything in the vendor folder (installed by Composer):

"search.exclude": {
    "vendor/**": true
}

As this is a plain text file and lives in its own segregated directory, it can (and should!) be committed to version control.

If you prefer to add exclusions through the UI, you can access the configuration with Ctrl + , (control key and a comma) and then look for ‘search’ under the Workspace section.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.