在 VS Code 中搜索时选择要忽略的文件夹 [英] Choose folders to be ignored during search in VS Code

查看:41
本文介绍了在 VS Code 中搜索时选择要忽略的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在当我使用+O搜索文件时,模糊匹配似乎对当前项目中的所有文件进行了操作.不幸的是,这包括来自 build 和 vendor 目录的许多文件.因此,例如,如果我想搜索所有 JavaScript 文件并执行 +O 并输入 .js,文件和符号结果包括大约 1500 次点击,除这两个之外的所有点击都是完全噪声.

有没有办法指定某些目录在搜索时被忽略?

解决方案

临时排除

在搜索功能中,单击省略号以显示 要包含的文件要排除的文件 文本框.输入要排除的任何文件和文件夹(以逗号分隔).

持续排除

从菜单中选择File ➡️ Preferences ➡️ Settings ➡️ User/Workspace Settings 并将默认设置过滤为search.

  • User 设置将应用于所有工作区
  • Workspace 设置将仅应用于此工作区

您可以修改 search.exclude 设置(从默认设置复制到您的用户或工作区设置).这仅适用于搜索.请注意,将自动应用 files.exclude 中的设置.

切换搜索排除

在使用 要排除的文件 文本框中的齿轮图标进行搜索时,您可以(有时会意外地)切换这些排除是启用还是禁用.点击省略号,然后点击齿轮图标进行切换.

更新设置后的搜索图片:

更新设置后,搜索结果正是我想要的.

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?

解决方案

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

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.

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 after updating settings:

After updating the settings the search results are exactly what I want.

这篇关于在 VS Code 中搜索时选择要忽略的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆