sublime中搜索应使用where输入框临时排除目录:如.,-/node_modules/,-*/node_modules/;永久配置需在.sublime-project中设folder_exclude_patterns,路径相对folders.path;全局设置仅影响侧边栏和ctrl+p,不影响find in files。

搜索时跳过 node_modules 等大目录,必须用 Where 输入框临时排除
Sublime 的「Find in Files」(Ctrl+Shift+F)默认扫整个项目,node_modules 一进去就是几万文件,结果里全是第三方库的 fetch、useState,根本找不到你写的那个。靠改用户设置或项目配置里的 folder_exclude_patterns 是不管用的——它只影响侧边栏显示和索引,不实时控制搜索范围。
真正起效的,是打开搜索面板后,在右下角 Where 输入框里手动写规则:
-
.表示当前项目根目录 -
-/node_modules/排除根目录下的node_modules(注意开头的/和结尾的/) -
-*/node_modules/排除所有层级的node_modules(比如packages/foo/node_modules) - 多个规则用英文逗号分隔:
., -/dist/, -/build/, -*.log(逗号前后不能有空格)
常见错误:写成 -node_modules 或 -node_modules/ → 不生效;写成 -my_node_modules → 可能误伤其他名字带 node_modules 的目录。
永久生效要配 .sublime-project,但路径是相对 folders.path 的
如果你总在同一个项目里搜代码,不想每次输一遍 Where,就得配项目级设置。关键是:这个配置不是写在用户首选项里,而是必须保存为 .sublime-project 文件,并且 folder_exclude_patterns 里的路径是相对于 folders.path 的,不是相对于项目文件本身。
比如你的项目结构是:
myapp/ ├── .sublime-project ├── src/ │ └── index.js └── node_modules/
那么 .sublime-project 应该这么写:
{
"folders": [
{
"path": "."
}
],
"settings": {
"folder_exclude_patterns": ["node_modules", "dist", ".git"],
"file_exclude_patterns": ["*.log", "*.tmp"]
}
}
如果 path 写的是 "src",那 "node_modules" 就得改成 "../node_modules" 才对——这点极容易搞反,改完还搜得到 .git,大概率是路径写错了或者拼成了 .gir。
全局忽略所有项目的 .git 和 venv,改用户设置但别关索引
想让每个新打开的项目都默认不显示 .git、venv、__pycache__?可以改用户设置(Preferences → Settings 右侧),加这两行:
"folder_exclude_patterns": [".git", "node_modules", "venv", "__pycache__"], "file_exclude_patterns": ["*.log", "*.tmp", "*.DS_Store"]
但注意:index_files: false 虽然能提升大项目响应速度,也会导致 Ctrl+P 模糊搜索变慢、甚至搜不到刚新建的文件。除非你真卡到没法工作,否则别关索引。这个设置只影响侧边栏和 Ctrl+P,对 Find in Files 依然无效——它还是得靠 Where 或项目配置。
Python 项目常漏掉 __pycache__ 和 *.pyc,搜索前先确认是否被排除
Python 用户经常遇到:改了 utils.py,搜索 def helper 却在结果里看到一堆 utils.cpython-311.pyc 里的重复匹配。这是因为 file_exclude_patterns 默认不包含 *.pyc,而 __pycache__ 文件夹也常被忘记加进 folder_exclude_patterns。
建议在项目配置或用户设置中统一加上:
"folder_exclude_patterns": ["__pycache__"]"file_exclude_patterns": ["*.pyc", "*.pyo", "*.pyd"]
验证方法很简单:打开 Ctrl+P,输入 utils.cpython,如果还能出来结果,说明没生效;再检查引号、逗号、大小写——__pycache__ 有两个下划线,少一个就白配了。
最麻烦的不是不会配,而是以为配了就万事大吉,结果搜索还跳出 node_modules 里的东西。记住:项目配置要刷新侧边栏才可见,Where 规则每次都要手输或复制,而全局设置只管“看得到看不到”,不管“搜得到搜不到”。三者作用域完全不同,混用就会失效。










