Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Choose folders to be ignored during search in VS Code

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?

like image 812
J. Abrahamson Avatar asked Apr 30 '15 15:04

J. Abrahamson


People also ask

How do I ignore code in VS Code?

Press Alt+Enter. From the pop-up menu, select Ignore All Errors in This File.

How do I search for a specific directory in VS Code?

Search across files. VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.


2 Answers

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.

like image 117
Shotty Avatar answered Oct 15 '22 07:10

Shotty


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

like image 36
atreeon Avatar answered Oct 15 '22 06:10

atreeon