Choose folders to be ignored during search in VS C

2020-01-27 09:22发布

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?

14条回答
我只想做你的唯一
2楼-- · 2020-01-27 09:56

Exclude all from subfolders works like this (version 2019)

include

./db

exclude

./db/*
查看更多
乱世女痞
3楼-- · 2020-01-27 09:59

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.

查看更多
SAY GOODBYE
4楼-- · 2020-01-27 10:01

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

查看更多
forever°为你锁心
5楼-- · 2020-01-27 10:02

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

查看更多
在下西门庆
6楼-- · 2020-01-27 10:02

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

查看更多
倾城 Initia
7楼-- · 2020-01-27 10:03

These preferences appear to have changed since @alex-dima's answer.

Changing settings

From menu choose: Preferences -> Settings -> User/Workspace Settings. Filter default settings to search.

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.

If the settings don't work:

  1. Make sure you dind't turn the search exclusion off. In the search area, expand the "files to exclude" input box and make sure that the gear icon is selected.

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

Example settings

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

查看更多
登录 后发表回答