VSCode:设置搜索时的排除目录

VSCode搜索时默认会搜索目录下所有文件

$ tree .

├── a.c

├── m.c

└── x

└── b.c

cpp 复制代码
//a.c
#include <stdio.h>
#include <string.h>

int main()
{
    char s[] = "hello\n";
    fprintf(stdout, s, strlen(s));
    return 0;
}
cpp 复制代码
//m.c
#include <stdio.h>
#include <string.h>

int main()
{
    char s[] = "hello, 88\n";
    fprintf(stdout, s, strlen(s));
    return 0;
}
cpp 复制代码
//b.c
#include <stdio.h>
#include <string.h>

int main()
{
    char s[] = "hi\n";
    fprintf(stdout, s, strlen(s));
    return 0;
}

可以看到当搜索main时,a.c,b.c和m.c中的main都被搜索到了

有时文件太多,或者有些文件或目录可以不用关注,这时可以通过设置排除目录和文件来实现

方法如下:

1.在项目目录(也就是vscode打开的目录)下创建子目录**.vscode**

2.在**.vscode子**目录下创建文件settings.json,文件内容如下:

javascript 复制代码
{
    "search.exclude": {
        "**/m.c": true,
        "x/": true,
    }
}

其中"**/m.c"表示任意目录下的m.c文件都会被排除搜索

"x/"表示目录x下的任意文件都会被排除搜索

此时通过vscode搜索

可以看到只搜索到了文件a.c,达到了目的

相关推荐
女神下凡6 小时前
这是 Cursor(Composer) 的五种核心交互模式
服务器·人工智能·windows·vscode·microsoft
生信碱移8 小时前
Vscode 连接 ipynb 选择内核无法自动显示 conda 环境对应的 python
服务器·人工智能·经验分享·vscode·python
爱就是恒久忍耐9 小时前
VSCode里clangd如何配置跳转
ide·vscode·编辑器
SmartManWind9 小时前
vscode中claude-code插件wsl中开启自动模式
ide·vscode·编辑器·claude code
Watink Cpper10 小时前
VSCode通过ChatGPT5.5登陆codex:sign-in could not be complete 问题解决方案
ide·vscode·编辑器·codex·gpt5.5
小庞在加油1 天前
从qmake到CMake+VSCode:Qt项目现代化迁移与AI提效实战指南
vscode·qt·ai·ai工具
utf8mb4安全女神1 天前
HTML网页【vscode】【Linux】
ide·vscode·编辑器
S-码农1 天前
vscode 通过 SSH 远程控制 Ubuntu
vscode·ubuntu·ssh
A.说学逗唱的Coke2 天前
【大模型专题】AI Copilot 完整实践指南:VSCode + GitHub Copilot Agent 模式全攻略
人工智能·vscode·copilot