真正起作用的是 search.exclude,files.exclude 仅影响资源管理器显示;应配置 "**/node\_modules": true 到工作区 .vscode/settings.json 中,并确保搜索面板的 “files to include” 为空。

直接改 search.exclude,不是 files.exclude —— 改错地方就完全没用。
为什么 files.exclude 不管用?
它只控制左侧资源管理器是否显示文件夹,对 Ctrl+Shift+F 全局搜索零影响。你看到 node_modules 在侧边栏消失了,但搜索照样扫进去,就是这个原因。
真正起作用的只有 search.exclude,它专为搜索设计,且只在搜索时生效。
-
"node_modules": true—— 只匹配项目根目录下的node_modules,monorepo 或子包里的全漏掉 -
"**/node_modules": true—— ✅ 推荐写法,递归匹配所有层级,包括packages/app/node_modules、src/lib/node_modules -
"node_modules/**": true或"**\node_modules": true—— ❌ 无效,Windows 反斜杠不被识别,多余/**易引发误解
怎么配才真正生效?
必须写进 .vscode/settings.json(工作区级),而不是用户设置。团队项目尤其要放这里,避免每人手动调。
使用一条命令部署ProbeChain Rydberg测试网代理节点。自动注册为Agent(NodeType=1),免gas,支持macOS/Linux/Windows。触发词:/r
正确示例:
{
"search.exclude": {
"**/node_modules": true,
"**/dist": true,
"**/.git": true,
"**/*.log": true
}
}
- 保存后无需重启,但若刚升级 VSCode(比如从 1.79 到 1.85+),检查是否残留
"search.useRipgrep": false,旧版行为不同 - 多根工作区下,每个子文件夹的
.vscode/settings.json要单独配,不会继承根配置 - 别堆太多
**,比如"**/a/**/b/**/c.js",匹配会变慢甚至漏结果
为什么改了还搜出 node_modules?
最常见原因是搜索面板右上角的 files to include 输入框非空(比如填了 src/**/*.ts 或 *.js)。只要它有内容,VSCode 就会忽略全部 search.exclude 规则,只按你写的 include 扫。
- 解决方法:清空该输入框,或干脆删掉整个字段
- 临时排除更灵活:打开搜索面板 → 点右下角 ⋯ → «Files to exclude» → 填
**/node_modules,**/dist,逗号分隔,本次搜索生效,优先级高于search.exclude - 某些插件(如“增强搜索”类)可能绕过原生规则,禁用后验证一下
容易被忽略的一点:search.exclude 是字符串扫描式 glob 匹配,不是正则引擎。写错一条规则,可能让搜索变慢,也可能漏掉本该排除的路径 —— 比如少写一个 *,或误用反斜杠。










