14

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

18

In your settings.json:

"search.exclude": { "**/node_modules": true, "**/bower_components": true, "**/builds": true } 
Sign up to request clarification or add additional context in comments.

5 Comments

Is there a way to also exclude them from the Cmd-t file search
Try using jsconfig (include or exclude options). Add this to your jsconfig.json: "exclude": ["node_modules", "builds"]
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.
You can try typing json or workspace in Command Palette. For me the command is Preferences: Open Workspace Settings.
The OP wants to ignore not just from search, but from edit, therefore @Frederiko Ribeiro's answer using "files.exclude" is preferable
10

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 Comments

No need to create a new file; just add the code into settings.json in the .vscode directory in your project
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
6

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

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.