Last updated: Apr 6, 2024
Reading time·6 min
If you need to exclude files or folders from the current search:
Press Ctrl
+ Shift
+ F
(or Cmd
+ Shift
+ F
on macOS) to show the
search menu in the left sidebar.
Click on the three dots (ellipsis) icon to show the files to exclude field.
Here is a short clip that demonstrates the process.
You can use the following format to exclude files and folders from the search.
**/package-lock.json
- exclude files named
package-lock.json located in any
directory.*.ts
- exclude all files with .ts
extension.**/node_modules
- exclude all files in the node_modules
directory.**/.git
- exclude all files in the .git
directory.wp-*.*
- exclude all files that start with wp-
.wp-config.*
- exclude all files that start with wp-config.
followed by any
extension.**
(two asterisks) are included at the beginning of the pattern, it covers the search term over all folders and subfolders (including the root directory).If you need to exclude multiple files or folders, separate them by a comma.
For example, .gitignore,example.ts
excludes the .gitignore
and example.ts
files from search.
Similarly, **/node_modules,**/.git
, excludes the node_modules
and .git
folders from search.
There is also an icon that allows you to search only in open editors.
When the icon to the right of the files to include field is clicked, the search results only contain matches from the currently opened files.
You can click on the icon again to disable the search only in open editors functionality.
If you need to exclude folders globally, from all searches:
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
The Search: Exclude setting allows you to configure glob patterns for excluding files and folders in full-text searches.
For example, to exclude node_modules
from the search, you would use the
following pattern:
**/node_modules
To exclude Thumbs.db
files located in any directory, you would use the
following pattern:
**/Thumbs.db
To exclude files that end with *.code-search
located in any directory, you
would use the following pattern:
**/*.code-search
If you scroll up with the Settings tab opened, you will see the Files: Exclude setting.
Note that the patterns that are specified under Files: Exclude are automatically excluded from the search.
If you only want to exclude files and folders from all searches but only applied to the current project (and not all projects of the logged-in user), configure the setting scoped to your Workspace.
Ctrl
+ Shift
+ P
(or Command
+ Shift
+ P
on macOS).F1
to open the Command Palette.You can also open the settings screen by pressing Ctrl
+ ,
on Windows and
Linux or Cmd
+ ,
on macOS.
Once you add patterns to the workspace Search: Exclude setting, you can view
the added patterns in your .vscode/settings.json
file.
You can use the same syntax to manually add exclude patterns to your
.vscode/settings.json
file.
{ "search.exclude": { "**/my-folder": true, "**/your-folder": true } }
Sometimes you might need to turn off the global search exclusions that you've previously set.
You can use a button to toggle global search exclusion patterns.
Press Ctrl
+ Shift
+ F
(or Cmd
+ Shift
+ F
on macOS) to show the
search menu in the left sidebar.
Click on the three dots (ellipsis) icon to show the files to exclude field.
By default, the Use Exclude Settings and Ignore Files functionality is enabled.
Here is a short clip that demonstrates how to toggle global search exclusions.
Always make sure to leave the Use Exclude Settings and Ignore files cogwheel selected after you're done.
Otherwise, you will get confused the next time you search and see results from folders that you've already excluded.
If the exclude patterns aren't applied correctly or you get incorrect search results, try to clear your editor history.
Ctrl
+ Shift
+ P
on Windows and LinuxCommand
+ Shift
+ P
on macOSF1
to open the Command Palette.Another thing that often causes issues is forgetting to enable the Use Exclude Settings and Ignore Files cogwheel button.
If the button is disabled, your Files: Exclude setting is completely ignored.
If you need to exclude multiple files or folders, separate them by a comma.
For example, .gitignore,example.ts
excludes the .gitignore
and example.ts
files from search.
Similarly, **/node_modules,**/.git
, excludes the node_modules
and .git
folders from search.
You can use the following format to exclude files and folders from the search.
**/package-lock.json
- exclude files named package-lock.json
located in
any directory.*.ts
- exclude all files with .ts
extension.**/node_modules
- exclude all files in the node_modules
directory.**/.git
- exclude all files in the .git
directory.wp-*.*
- exclude all files that start with wp-
.wp-config.*
- exclude all files that start with wp-config.
followed by any
extension.You can read more about the glob syntax in this section of the docs.
The most commonly used glob characters are:
*
- matches zero or more characters in a path segment.?
- matches exactly one character in a path segment.**
- matches any number of characters in a path segment or no characters at
all. For example, **/node_modules
matches a node_modules
folder in the
root directory or a nested directory.{}
- is used to group conditions. For example, {**/*.js,**/*.ts}
matches
all JS and TS files.[]
- is used to specify a range of characters or numbers to match. For
example, foo_[0-9]
matches foo_0
, foo_1
, foo_2
, etc.[!...]
- is used to negate a range of characters to match. For example,
foo_[!0-9]
matches foo_a
and foo_b
, but not foo_0
and foo_1
.I've also written a detailed guide on how to search all files in VS Code.
You can learn more about the related topics by checking out the following tutorials: