Exclude files from VS Code search… and share it with the team!

I see many developers use Visual Studio Code as a tool helping them perform a quick full-text search in their code. And for a good reason. You can open a folder in VS Code and find fragments of text in just seconds!

However, sometimes we might want to ignore (hide) some files from search results. Developers almost always look for something in their source code, but rarely in build artifacts like cache, compiled files, or third-party modules.

The following screenshot shows a search results in a simple Angular app. Only one search result is practically useful, and 6 others are just garbage in a generated code in the cache:

Even in a simple app, irrelevant search results can clutter the view and make it more difficult to find what we need.

How to ignore folders from search results for ourselves?

Visual Studio Code allows us to exclude some files and folders from search. It’s as simple as adding a piece of configuration to your settings.json file, and it will be applied to all folders you open:

We can alter our personal VS Code settings to hide such search results.

How to share the configuration in the team?

While solving the problem for yourself is great, solving it for the whole team is much cooler 😎 And it’s as simple as adding the settings in the file named:

.vscode/settings.json

… which you check in to your git repository, instead of to your personal settings.json file. Example of the file content:

{
  "search.exclude": {
    "/.angular/cache": true,
    "/dist/": true
  }
}Code language: JSON / JSON with Comments (json)

And this is how it changes the search results. Much better now, eh? 🙂

Decluttered search results, after files from /.angular/cache folder were excluded from search results.
No comments yet, you can leave the first one!

Leave a Comment