12

I have a /builds directory that has some compiled JS inside and I find myself accidentally editing files in there rather than the ones in the rest of the project that I want to edit because Cmd-T brings up 2 files and I just pick the first, quickly.

How can I ignore a file or a directory in my specific project in VS Code? Thanks!

4 Answers 4

15

In your settings.json:

"search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/builds": true
}
5
  • 4
    Is there a way to also exclude them from the Cmd-t file search Commented Jul 24, 2017 at 19:13
  • Try using jsconfig (include or exclude options). Add this to your jsconfig.json: "exclude": ["node_modules", "builds"]
    – Alex
    Commented Jul 24, 2017 at 19:57
  • 2
    How can I find settings.json for the project or workspace? I only can open settings.json for the entire application, which I assume applies to all projects. Commented Mar 13, 2019 at 14:24
  • 1
    You can try typing json or workspace in Command Palette. For me the command is Preferences: Open Workspace Settings.
    – Alex
    Commented Mar 13, 2019 at 14:35
  • The OP wants to ignore not just from search, but from edit, therefore @Frederiko Ribeiro's answer using "files.exclude" is preferable
    – Psionman
    Commented Apr 30 at 7:03
6

What I recommend:

Create a file in the root of your application named myProject.code-workspace and edit it like this:

{
  "folders": [
    {
      "path": "."
    }
  ],
  "settings": {
    "search.exclude": {
      "**/node_modules": true,
    },
    "files.exclude": {
      "**/android": true,
      "**/ios": true,
    },
    "editor.formatOnSave": true, // not needed
  }
}

In this way your project will ignore the files in the "explore" tab. if you want to exclude the files only for the search environment, add it to search.exclude, otherwise to files.exclude in the settings rules. You can add/edit as you want.

VSCode will detect that file and consider it as the JSON for the workspace config. Don't forget to open this workspace in your VSCode by going to file > open workspace and select this file.

For more info: https://code.visualstudio.com/docs/getstarted/settings

2
  • 2
    No need to create a new file; just add the code into settings.json in the .vscode directory in your project
    – Psionman
    Commented Apr 30 at 7:05
  • Yes, that's also true. But I usually prefer to create this one xD Since not all the devs in the same project uses .vscode, it is more explicity Commented May 1 at 19:52
4

The best way to achieve this for me was to instruct VScode to use the .gitignore file. This prevents both the explorer view and searches to skip patterns matching the .gitignore. In settings.json:

{
    "explorer.excludeGitIgnore": true,
}
1

First open settings: in OSX "CMD + ,". Or go to the menu Code -> Preferences -> Settings. Or search "open user settings" in the commmand palette: Search settings in VSCode

In Features -> Search press the Add Pattern button. Write your folder name, like the examples.

Important: If the folder has to be excluded for several projects, set this in the user tab (at the top of the screen), as a global setting. But, if this is only a one-time setting, switch to the workspace tab (next to User).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.