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,达到了目的

相关推荐
面壁的熊猫2 小时前
cursor+cline+MCP(论文agent)
vscode·agent·cursor·mcp
Aspect of twilight5 小时前
vscode python debug方式
ide·vscode·python·debug
啃火龙果的兔子7 小时前
vscode中可以使用的免费的AI编程工具有哪些
ide·vscode·ai编程
littlezls7 小时前
在VSCode中运行Python脚本文件时如何传参
vscode·python
宋明炜8 小时前
VSCode + MSYS2 配置 C 语言开发环境(详细步骤)
c语言·ide·vscode
yscript8 小时前
GPU分配BUG: Duplicate GPU detected : rank 1 and rank 0 both on CUDA device d5000
linux·运维·服务器·vscode·bug
shhpeng9 小时前
Visual Studio Code 下 go 开发环境搭建
ide·vscode·编辑器
newobut19 小时前
vscode远程调试python程序,基于debugpy库
vscode·python·调试·debugpy
潮流coder1 天前
vscode修改缓存保存路径
ide·vscode·缓存
承接电子控制相关项目1 天前
安装VSCODE发现 右击选项中无VSCODE 打开选项,处理方法汇总
ide·vscode·编辑器