REW

How Do You Exclude Search Vs Code?

Published Aug 29, 2025 4 min read
On this page

In Visual Studio Code, you can exclude files and folders from the search in several ways, from temporary exclusions in the search panel to permanent settings that can be configured for a specific workspace or your entire user profile.

The most effective and detailed methods involve using the search.exclude and files.exclude settings.

Method 1: The search.exclude setting

This setting is the most precise way to control what is excluded from the full-text search feature. It offers control at both the user and workspace levels.

Setting up search.exclude

  1. Open Settings: Use the keyboard shortcut Ctrl + , (Windows/Linux) or Cmd + , (macOS).
  2. Choose Scope: Decide if your changes should apply to all projects (User settings) or only the current project (Workspace settings). The Workspace setting will override the User setting.
  3. Find search.exclude: Type search exclude into the settings search bar.
  4. Add a pattern: Click the "Add Pattern" button and enter a glob pattern to define which files or folders to exclude. For example, **/node_modules will exclude all folders named node_modules wherever they appear in your project.

The anatomy of search.exclude

The search.exclude setting is an object in settings.json that maps glob patterns to boolean values.

"search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/*.log": true
}

Use code with caution.

  • **/node_modules: Excludes the node_modules folder and all its contents from search, no matter where it is located in the project hierarchy.
  • **/*.log: Excludes all files with a .log extension from the search.
  • **/dist/**/*: Excludes all files and subfolders within any dist folder.

Method 2: The files.exclude setting

This setting is broader and is primarily used to hide files and folders from the Explorer view, but it also applies to search by default. Any pattern added here will be respected by the search functionality.

Setting up files.exclude

  1. Open Settings: Press Ctrl + , (Windows/Linux) or Cmd + , (macOS).
  2. Choose Scope: Select User or Workspace settings.
  3. Find files.exclude: Search for files exclude.
  4. Add a pattern: Use the "Add Pattern" button to specify files and folders to exclude. For example, **/build will hide the build output folder from both the Explorer and searches.

The anatomy of files.exclude

The structure is similar to search.exclude.

"files.exclude": {
    "**/.git": true,
    "**/.DS_Store": true,
    "**/node_modules": true
}

Use code with caution.

  • You will notice that some patterns like **/.git and **/node_modules are often included by default for common projects.

Method 3: Temporarily excluding from the search panel

For quick, one-off exclusions that don't require permanent settings, you can use the search panel directly. This is useful for temporarily focusing your search without changing your settings.

How to use the search panel

  1. Open Search: Press Ctrl + Shift + F (Windows/Linux) or Cmd + Shift + F (macOS).
  2. Toggle Details: Click the ellipsis (...) to reveal the "files to exclude" input field.
  3. Enter pattern: Type your exclusion patterns, separated by commas. For example, to search for a term but ignore the test directory, you would enter **/test in the "files to exclude" field.
  4. Important: These exclusions are only active for the current search session.

Method 4: Using .gitignore files

If your project is under version control with Git, you can leverage your .gitignore file to manage search exclusions. This is especially helpful for keeping your search in sync with your version control strategy.

How to enable .gitignore for search

  1. Open Settings: Navigate to your settings (Ctrl + , or Cmd + ,).
  2. Search for ignore: Look for the Search: Use Ignore Files setting.
  3. Enable the setting: Ensure this setting is checked. With this enabled, VS Code will automatically use the patterns in your .gitignore file to exclude files and folders from search results.

Enabling Use Exclude Settings and Ignore Files

When using the search panel, there is a gear icon (cogwheel) next to the "files to exclude" field. Click this to toggle whether your global/workspace exclude settings and .gitignore files are honored. If you are not seeing expected exclusions, make sure this icon is selected.

A hierarchy of exclusion methods

Understanding the different methods in Visual Studio Code is key to managing your search scope effectively. Here is a quick summary of the hierarchy, from most temporary to most permanent:

  • Search Panel: Quick, temporary exclusions for a single search.
  • .gitignore: Inherits exclusions from your version control setup. A powerful, project-standard approach.
  • Workspace settings.json: Permanent exclusions that are specific to the current project and can be shared with your team.
  • User settings.json: Global exclusions that apply to all projects opened by your user.
Enjoyed this article? Share it with a friend.