Zack Shapiro
Zack Shapiro

Reputation: 6998

Ignore files or folders in VS Code

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!

Upvotes: 13

Views: 15478

Answers (4)

Michel
Michel

Reputation: 1523

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,
}

Upvotes: 5

LightMan
LightMan

Reputation: 3575

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).

Upvotes: 1

Frederiko Ribeiro
Frederiko Ribeiro

Reputation: 2358

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

Upvotes: 8

Alex
Alex

Reputation: 67473

In your settings.json:

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

Upvotes: 17

Related Questions