选择在VS Code中搜索期间要忽略的文件夹

本文介绍了如何在Visual Studio Code(VS Code)中指定搜索时要忽略的文件夹,以避免在搜索时受到构建目录和供应商目录等干扰。用户可以通过修改工作区或全局设置来实现这一功能,例如在`search.exclude`中添加特定目录,或者使用`Clear Editor History`命令排除已搜索过的文件。
部署运行你感兴趣的模型镜像

本文翻译自: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. 现在,当我使用 + O搜索文件时,模糊匹配似乎可以对当前项目中的所有文件进行操作。 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. 因此,例如,如果我要搜索所有JavaScript文件并执行 + O,然后输入.js ,则文件和符号结果包括大约1500次匹配,除两个匹配之外,所有匹配均为完全干扰。

Is there a way to specify certain directories to be ignored for purpose of search? 有没有一种方法可以指定出于搜索目的而忽略的某些目录?


#1楼

参考:https://stackoom.com/question/21kyu/选择在VS-Code中搜索期间要忽略的文件夹


#2楼

This answer is outdated 这个答案已经过时了

If these are folders you want to ignore in a certain workspace, you can go to: 如果这些是您要在特定工作空间中忽略的文件夹,则可以转到:

AppMenu > Preferences > Workspace Settings

Otherwise, if you want these folders to be ignored in all your workspaces, go to: 否则,如果要在所有工作空间中忽略这些文件夹,请转到:

AppMenu > Preferences > User Settings

and add the following to your configuration: 并将以下内容添加到您的配置中:

//-------- Search configuration --------

// The folders to exclude when doing a full text search in the workspace.
"search.excludeFolders": [
    ".git",
    "node_modules",
    "bower_components",
    "path/to/other/folder/to/exclude"
],

The difference between workspace and user settings is explained in the customization docs 定制文档中说明工作空间和用户设置之间的区别


#3楼

These preferences appear to have changed since @alex-dima's answer. 自@ alex-dima回答以来,这些首选项似乎已更改。

Changing settings 变更设定

From menu choose: Preferences -> Settings -> User/Workspace Settings. 从菜单中选择:首选项->设置->用户/工作区设置。 Filter default settings to search . 过滤默认设置进行search

You can modify the search.exclude setting (copy from default setting to your user or workspace settings). 您可以修改search.exclude设置(从默认设置复制到用户或工作空间设置)。 That will apply only to searches. 这仅适用于搜索。 Note that settings from files.exclude will be automatically applied. 请注意, files.exclude中的设置将被自动应用。

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 ). 您可能还需要清除编辑器历史记录(请参阅: 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. 例如,我正在开发一个EmberJS应用程序,该应用程序将数千个文件保存在tmp目录下。

If you select WORKSPACE SETTINGS on the right side of the search field, the search exclusion will only be applied to this particular project. 如果在搜索字段的右侧选择“ WORKSPACE SETTINGS ”,则搜索排除项将仅应用于此特定项目。 And a corresponding .vscode folder will be added to the root folder containing settings.json . 相应的.vscode文件夹将被添加到包含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. 更新设置后,搜索结果正是我想要的。

更新设置后的搜索图片。


#4楼

If I understand correctly you want to exclude files from the vscode fuzzy finder. 如果我理解正确,则想从vscode模糊查找器中排除文件。 If that is the case, I am guessing the above answers are for older versions of vscode. 如果是这样,我想上面的答案是针对旧版本的vscode。 What worked for me is adding: 对我有用的是添加:

"files.exclude": {
    "**/directory-you-want-to-exclude": true,
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true
}

to my settings.json . 到我的settings.json This file can be opened through File > Preferences > Settings 可以通过File > Preferences > Settings打开此文件


#5楼

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). 设置先前答案中提到的search.exclude和file.exclude之后,运行命令“清除编辑器历史记录”(使用命令面板执行此操作-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. 我忘记了。


#6楼

Make sure the 'Use Exclude Settings and Ignore Files' cog is selected 确保已选中“使用排除设置并忽略文件”齿轮 在此处输入图片说明

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

### VSCode 扩展在 VS 关闭后开始安装的原因分析 当用户报告 VSCode 的扩展会在关闭应用后再开始安装时,这通常是由于以下几个原因造成的: #### 1. **后台进程处理机制** VSCode 使用了一种异步的任务队列管理方式来处理扩展的下载和安装过程。即使用户主动触发了扩展安装的操作,在某些情况下,实际的安装任务可能被推迟到稍后的时刻执行。这种行为可能是为了优化资源分配或减少对当前运行环境的影响[^1]。 如果用户在此期间选择了退出程序,则未完成的任务会被移交给后台服务继续执行。因此,尽管看起来是在关闭应用程序之后才启动安装流程,但实际上这是先前已安排好的任务延续的结果。 #### 2. **网络连接延迟影响** 另一个可能导致此类现象的因素涉及到了外部服务器之间的通信状况。假如存在较长时间的数据传输等待期或者是重试逻辑的话,那么整个操作周期就会延长很多;再加上前面提到过的调度策略共同作用之下,就更容易观察到上述情况的发生——即直到最后阶段(比如完全退出界面)前都还没有真正意义上结束全部必要的准备工作【^4】. 另外值得注意的一点在于有些特定类型的插件它们本身体积较大或者依赖其他组件也需要额外时间去获取这些相关内容从而进一步增加了整体所需耗时长度所以才会显得更加明显地表现出这样的特点出来。 #### 解决方案建议 针对这种情况可以从多个角度入手寻找改善办法: - #### 更新至最新版 确保使用的VisualStudioCode版本是最新的因为开发者团队断改进产品性能其中包括提高对于各种异常情形下的响应速度以及稳定性等方面的表现通过升级可以获得更好的体验效果同时也减少了遇到类似问题的可能性【^2】 - #### 调整设置参数 可以尝试修改部分默认设定项例如增加超时时限数值允许更长的时间用于等待远程资源返回数据这样有助于缓解因短暂性的网络波动所引起的中断风险同时也能让系统有更多机会顺利完成预定目标而至于轻易放弃进而转而采取后续措施如前所述那样等到下次开机再继续进行下去的情况发生频率降低下来 以下是具体如何调整的一个例子代码片段展示: ```json { "http.proxy": "", "http.proxyStrictSSL": false, "extensions.autoUpdate": true, "search.useIgnoreFiles": false } ``` 其中涉及到几个关键字段解释如下: - `http.proxy`: 如果需要代理则留空否则填写相应的地址信息; - `http.proxyStrictSSL`: 设置为false表示忽略证书验证错误适合特殊环境下使用; - `extensions.autoUpdate`: 开启自动更新功能保持各附加模块始终处于最佳状态可用性最高; - `search.useIgnoreFiles`: 防止遗漏重要文件夹内的潜在匹配项提升全局查找效率; - #### 清理缓存记录 定期清除掉必要的临时存储资料可以帮助释放更多的磁盘空间并加快读写速率间接促进各项事务进展顺利程度得到增强包括但限于这讨论的主题范围之内同样适用此方法论原则来进行维护管理工作实践证明往往能够取得错的效果反馈回来给使用者带来便利之处多多益善矣乎哉焉耳矣! --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值