在 VSCode 左侧搜索时排除多个文件夹,可通过修改工作区或全局的 settings.json 文件,使用 search.exclude 和 files.exclude 功能实现。具体操作如下:
settings.json 文件配置.vscode 文件夹(若不存在),然后在其中新建 settings.json 文件。Ctrl + , 或 Cmd + ,)进入,找到并编辑用户设置文件。settings.json 文件中,使用 search.exclude 字段排除搜索时不需要显示的文件夹,使用 files.exclude 字段排除资源管理器中不需要显示的文件夹。{
"search.exclude": {
"**/node_modules": true, // 排除所有 node_modules 文件夹
"**/dist": true, // 排除所有 dist 文件夹
"**/build": true, // 排除所有 build 文件夹
"**/logs": true // 排除所有 logs 文件夹
},
"files.exclude": {
"**/node_modules": true, // 在资源管理器中隐藏 node_modules 文件夹
"**/dist": true, // 在资源管理器中隐藏 dist 文件夹
"**/build": true, // 在资源管理器中隐藏 build 文件夹
"**/logs": true // 在资源管理器中隐藏 logs 文件夹
}
}settings.json 文件。Ctrl + ,(Windows/Linux)或 Cmd + ,(Mac)打开 VSCode 的设置界面。search.exclude 或 files.exclude。Add Pattern)按钮。**/node_modules),并选择启用(true)。*:匹配任意单个字符或文件名。**:匹配任意路径(包括子目录)。**/temp/* 排除所有 temp 文件夹下的文件。search.exclude 或 files.exclude 中,可以使用正则表达式来定义更复杂的排除规则。**/[!a-z]* 排除所有不以小写字母开头的文件夹。.vscode/settings.json)会覆盖全局用户设置。search.exclude 仅影响搜索结果,files.exclude 影响资源管理器中的显示。