699

Right now when I use +O to search for files, the fuzzy matching appears to operate over all files in the current project. Unfortunately, this includes a number of files from build and vendor directories. So, for instance, if I want to search for all JavaScript files and do +O and type .js in, the file and symbol results include around 1500 hits and all of them except the two ones are complete noise.

Is there a way to specify certain directories to be ignored for purpose of search?

divenex
  • 15,176
  • 9
  • 55
  • 55
J. Abrahamson
  • 72,246
  • 9
  • 135
  • 180
  • 1
    Hmm, wait a minute, in 2019 ⌘O means "Open File...", and I doubt VS Code has much control over whatever (OS-specific) search facilities you might see there. It *might* be able to filter the files to only certain extensions? – SamB May 30 '19 at 23:32
  • 1
    Is this similar to Command +T now? I see stuff from node_modules when I prefix m search with # in the global search. – Nick Sep 14 '20 at 19:15
  • 4
    **Related settings** I was looking for: `search.useIgnoreFiles` `search.useGlobalIgnoreFiles` (tells search whether to pay attention to what's in gitignore to filter out what gets searched - I prefer this off in general, if I want it to filter something out I'll explicitly let it know) – Andrew Nov 10 '20 at 03:03
  • Press `CTRL + ,` then `search.exclude`. – T.Todua Jul 21 '22 at 20:02

20 Answers20

1215

Temporary Exclusions

From the search function, click the ellipsis to show the files to include and files to exclude text boxes. Enter any files and folder to exclude (separated by commas).

Picture of temporarily excluding files/folders by entering them in to the files to exclude text box.

Persistent Exclusions

From menu choose File ➡️ Preferences ➡️ Settings ➡️ User/Workspace Settings and filter default settings to search.

  • User settings will apply to all workspaces
  • Workspace settings will apply only to this workspace

You can modify the search.exclude setting (copy from default setting to your user or workspace settings). That will apply only to searches. Note that settings from files.exclude will be automatically applied.

Toggling search exclusions

You can (sometimes accidentally) toggle if these exclusions are enabled or disabled when searching using the gear icon in the files to exclude text box. Click the ellipsis, then the gear icon to toggle.

Picture of toggle instructions in the search field.

Additional documentation on configuring settings in Visual Studio Code

If the settings don't work

You might also need to Clear Editor History (See: https://github.com/Microsoft/vscode/issues/6502).

Example

I am developing an EmberJS application which saves thousands of files under the tmp directory.

If you select WORKSPACE SETTINGS on the right side of the search field, the search exclusion will only be applied to this particular project. And a corresponding .vscode folder will be added to the root folder containing settings.json.

This is my example settings:

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

Note: Include a ** at the beginning of any search exclusion to cover the search term over any folders and sub-folders.

Picture of search before updating settings:

Before updating the settings the search results are a mess.

Picture of search before updating settings

Picture of search after updating settings:

After updating the settings the search results are exactly what I want.

Picture of search after updating settings.

Shotty
  • 12,307
  • 2
  • 13
  • 5
  • 30
    this has stopped working for me in the recent version... any idea why? – NSjonas Nov 17 '16 at 20:35
  • Works in the latest v1.7.2 for mac. One possible gotcha: double-check that you wrapped the setting in a top-level object - without this it fails to work without a warning. – davnicwil Dec 05 '16 at 08:59
  • Seems that in 1.8 they've gone back (?) to having separate User and Workspace settings options in the Preferences menu. – Drew Noakes Jan 20 '17 at 15:15
  • I had to close and re-open the application to apply the new settings. – Tim Perkins Feb 02 '17 at 22:41
  • 10
    Is there a way to make this apply to the "Quick Open" feature? Ctrl+P on PC and Cmd+P on Mac. When i search for files using this feature, they still show up. – glandrum101 Feb 14 '17 at 16:35
  • 10
    Make sure to clear your editor history for this to work. https://github.com/Microsoft/vscode/issues/6502 – Jaydeep Solanki Mar 28 '17 at 22:21
  • 1
    Also note that there is `"files.exclude"` which will completely hide the files from the workspace. – Peter Lamberg Apr 05 '17 at 14:29
  • 1
    The menu option now is: `File -> Preferences -> Settings` And then you have to select either one of the tabs `USER SETTINGS` or `WORKSPACE SETTINGS` (at the right side of the search field) – Julian Cardenas May 11 '17 at 16:04
  • 5
    I had to run the command "clear editor history" (see here: https://github.com/Microsoft/vscode/issues/6502#issuecomment-273697138) and restart VS Code for this to work for me. – Isaac Gregson Oct 25 '17 at 16:14
  • 31
    Note that it is possible to turn the search exclusion off when searching files. In the search area, expand the "files to exclude" input box and make sure that the gear icon is selected. This will ensure your search exclusion settings are honored. – Robert Waddell Nov 07 '17 at 15:22
  • https://stackoverflow.com/questions/29971600/how-can-i-choose-folders-to-be-ignored-during-search/48847197#48847197 – atreeon Apr 27 '18 at 08:31
  • @shotty but how to exclude an extension from the search (eg: `.lnk`)? This failed: `"search.exclude": { ".lnk": true, },` – JinSnow May 31 '19 at 18:31
  • 3
    The gear icon in the "files to exclude" is super subtle—at least in my current theme, it's tough to see whether it's even selected. Super non-obvious! – Ben Coppock Jul 29 '19 at 19:44
  • concerning the exclude field: **you must specify the relative path** (from the workspace if you don't write anything in `include file`, VS code search in it. If you set an `include file`, specify the relative path from this point.) – JinSnow Oct 10 '19 at 09:47
  • I have "**/node_modules/" and "**/node_modules/*" added to both "search.exclude" and "files.exclude" in both user and workspace settings and yet node_module files still show up in search! How hard can it be to exclude a folder! – Ian Vaughan Apr 01 '20 at 14:21
  • If the folder is a git project, with a `.gitignore` file, then the search will exclude the patterns included on that file. People are asking to do the same for file visibility, [here](https://github.com/microsoft/vscode/issues/38878#issuecomment-540520454). I hope someday it will be implemented – ChesuCR Apr 29 '20 at 00:39
  • Setting `"search.useIgnoreFiles":false` was also required for me, as mentioned at https://dinohensen.nl/vscode-enable-searching-node-modules See also https://code.visualstudio.com/docs/getstarted/settings – Ryan Oct 25 '20 at 19:17
  • It's not working for me, is there anything else to do (from the settings.js file)? – Or Assayag Nov 07 '20 at 19:09
  • for me, it fixed I needed to use `Developer: Reload window` (type `>reload` after CMD/CTRL+P) – Juan José Ramírez Mar 04 '21 at 01:47
  • BTW, to clear the editor history, search the command palette (i.e., shift+ctrl+p, search for Clear Editor History). – Aaron B. Aug 24 '21 at 04:29
  • 1
    @RobertWaddell thank you sir. Must have accidentally toggled off my global exclusions. You saved my sanity! – Joe Van Leeuwen Aug 27 '21 at 14:52
  • @Ryan I would go crazy if I didn't have node_modules excluded from search. If you really need to look up the modules sources, have a separate VS Code window open just for that, with the node_modules folder open. Just switch between the windows to look up the docs. Another way would be to set up a custom .code-workspace file, you can list multiple folders there, add your project root and a separate node_modules folder. E.g. "folders": [ { "name": "root", "path": "./" }, { "name": "node_modules", "path": "node_modules/" } ] – Gene Pavlovsky Feb 06 '23 at 14:32
228

Make sure the 'Use Exclude Settings and Ignore Files' cog is selected enter image description here

atreeon
  • 21,799
  • 13
  • 85
  • 104
  • 22
    How would one exclude multiple folders? – Wouter Vanherck Sep 10 '18 at 14:51
  • 62
    @WouterVanherck you would just add a comma to separate each file or folder you want to exclude. Example: `./src/public/,src/components/` – Sgnl Dec 19 '18 at 01:08
  • 1
    Thank you! I never would have guessed that having that icon clicked was turning on and off my workspace settings. I spent hours thinking I was doing my settings incorrectly. – John Pankowicz Aug 26 '20 at 21:35
72

Update April 2018

You can do this in the search section of vscode by pre-fixing an exclamation mark to each folder or file you want to exclude.

enter image description here

Christopher Grigg
  • 2,238
  • 27
  • 33
43

I'm an idiot so it took me a while to realize this, but make sure that the Gear icon is clicked on the global search so your settings can be applied.

Visual Studio Code Gear Icon on Search clicked

Pants
  • 2,563
  • 1
  • 20
  • 34
  • 4
    you're not an idiot because this is the answer that fixed it for me, I must have accidentally clicked that icon in the past, it's so not obvious that this little icon controls this and it's barely noticeable when it's enabled or disabled – vesperknight Jun 15 '19 at 18:48
  • 3
    You're certainly not an idiot for missing that wonderful piece of UX, but can you tell me how yours is different than [this earlier answer](https://stackoverflow.com/a/48847197/1028230), if it is -- well, beyond this answer being in dark mode? ;^D – ruffin Apr 13 '20 at 20:20
  • @ruffin did not notice the earlier answer ha! I guess mine has better UX (the arrow) ;) – Pants Dec 18 '20 at 17:12
  • 2
    Ha! 22 people and counting agree, so who am I to argue? Least I didn't miss something obvious; thanks. – ruffin Dec 18 '20 at 18:08
  • 2
    Why is this button even a thing? In what universe do I set global settings and then want to turn off those global settings via a confusing button? – et071385 Mar 31 '22 at 18:26
42

If these are folders you want to ignore in a certain workspace, you can go to:

AppMenu > Preferences > Workspace Settings

Otherwise, if you want these folders to be ignored in all your workspaces, go to:

AppMenu > Preferences > User Settings

and add the following to your configuration:

//-------- Search configuration --------

// The folders to exclude when doing a full text search in the workspace.
"search.excludeFolders": [
    ".git",
    "node_modules",
    "bower_components",
    "path/to/other/folder/to/exclude"
],

The difference between workspace and user settings is explained in the settings docs

tagurit
  • 494
  • 5
  • 13
Alex Dima
  • 21,891
  • 1
  • 15
  • 14
31

If I understand correctly you want to exclude files from the vscode fuzzy finder. If that is the case, I am guessing the above answers are for older versions of vscode. What worked for me is adding:

"files.exclude": {
    "**/directory-you-want-to-exclude": true,
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true
}

to my settings.json. This file can be opened through File>Preferences>Settings

Nahush Farkande
  • 5,290
  • 3
  • 25
  • 35
  • 4
    FYI, this **also** excludes those files from the explorer window, not just search – Liam Mar 21 '22 at 13:36
16

Hi you need to find settings and add a new exclude pattern for history files

VSC Screenshot

Imad Eddin
  • 181
  • 2
  • 5
15

Create this file in your vscode project

.vscode/settings.json

{
  "search.exclude": {
    "**/Pods": true,
    "**/node_modules": true,
    "**/*.code-search": true
  }
}
david_adler
  • 9,690
  • 6
  • 57
  • 97
7

The short answer is to comma-separate the folders you want to ignore in "files to exclude".

  1. Start workspace wide search: CTRL+SHIFT+f
  2. Expand the global search with the three-dot button
  3. Enter your search term
  4. As an example, in the files to exclude-input field write babel,concat to exclude the folder "babel" and the folder "concat" in the search (make sure the exclude button is enabled).
  5. Press enter to get the results.
domih
  • 1,440
  • 17
  • 19
6

Since it was not mentioned before and some users wanted to know how to exclude multiple files or folders (temporarily) in an ad-hoc search:

You can exclude multiple files and folders from the search with a comma-separated list of simplified globbing patterns (as described in VS Code's glob.ts source:

/**
 * Simplified glob matching. Supports a subset of glob patterns:
 * * `*` to match one or more characters in a path segment
 * * `?` to match on one character in a path segment
 * * `**` to match any number of path segments, including none
 * * `{}` to group conditions (e.g. *.{ts,js} matches all TypeScript and JavaScript files)
 * * `[]` to declare a range of characters to match in a path segment (e.g., `example.[0-9]` to match on `example.0`, `example.1`, …)
 * * `[!...]` to negate a range of characters to match in a path segment (e.g., `example.[!0-9]` to match on `example.a`, `example.b`, but not `example.0`)
 */

And don't forget to activate the (⚙-) Use Exclude Settings and Ignored Files button on the Search Details panel (...) (following Shotty's explanations).

enter image description here

wp78de
  • 18,207
  • 7
  • 43
  • 71
5

I wanted to exclude 1 of the Workspace folders completely, but found this to be difficult, since regardless of the exclusion patterns, it always runs the search on each of the Workspace folders.

In the end, the solution was to add ** to the Folder Settings search exclusion patterns.

enter image description here

LStarky
  • 2,740
  • 1
  • 17
  • 47
4

After you setup the search.exclude and file.exclude mentioned on the previous answers, run the command "Clear Editor History" (Use the Command Palette to do that - CTRL + SHIFT + P).

Only after that the excluded files will not appear on your quick open menu.

Update: You can run the command "Clear Command History" too. I forgot about that.

Bruno Gimenes
  • 191
  • 1
  • 5
3

I added this to settings.json

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

after need enable it in settings panel

enter image description here

kostikovmu
  • 411
  • 5
  • 6
1

Forget aboves for vscode exclude search pattern, try to below pattern it is working for any folder in vscode last version!

!../../../locales/*

for example i have searched like below vscode example clude settings

files to include: *.js

files to exclude: **/node_modules,!../../../locales/,!../../../theme/,!../../admin/client/*

Hamit YILDIRIM
  • 4,224
  • 1
  • 32
  • 35
1

If you have multiple folders in your workspace, set up the search.exclude on each folder. There's a drop-down next to WORKSPACE SETTINGS.

Folder Settings Tab

Bhaskara Arani
  • 1,556
  • 1
  • 26
  • 44
1

Extending the most voted answer, now there is an extension to achieve what is described there to toggle quickly in a GUI way. It's called Explorer Exclude. You can install this with this command:

ext install PeterSchmalfeldt.explorer-exclude

Demo:

enter image description here

tagurit
  • 494
  • 5
  • 13
Touhid Rahman
  • 533
  • 5
  • 14
1

I am sure it must be resolved now but I just wanted to contribute my solution as well which may be easy and useful for someone.

simply type below line in exclude field of the search

*/node_modules/*

No need to set anything in the setting files of your workspace/VS Code.

Ambuj Khanna
  • 1,131
  • 3
  • 12
  • 32
0

Exclude all from subfolders works like this (version 2019)

include

./db

exclude

./db/*
-2

I wanted to search for the term "Stripe" in all files except those within a plugin ("plugin" folder) or within the files ending in ".bak", ".bak2" or ".log" (this is within the wp-contents folder structure of a wordpress install).

I just wanted to do this search one time and very quickly, so I didn't want to alter the search settings of my environment. Here's how I did it (note the double asteriks for the folder):

  • Search Term: Stripe
  • Include Files: {blank}
  • Exclude Files: *.bak*, *.log, **/plugins/**

Here's what it looked like

Adam
  • 31
  • 5
-4

Create a file with .gitignore & put the folder or file name which one you want to ignore.

to ignore everything below node_modules folder

echo node_modules/ > .gitignore 
reza.cse08
  • 5,938
  • 48
  • 39