选择在VS Code中搜索期间要忽略的文件夹

本文介绍了如何在Visual Studio Code(VS Code)中指定搜索时要忽略的文件夹,以避免在搜索时受到构建目录和供应商目录等干扰。用户可以通过修改工作区或全局设置来实现这一功能,例如在`search.exclude`中添加特定目录,或者使用`Clear Editor History`命令排除已搜索过的文件。
摘要由CSDN通过智能技术生成

本文翻译自:Choose folders to be ignored during search in VS Code

Right now when I use + O to search for files, the fuzzy matching appears to operate over all files in the current project. 现在,当我使用 + O搜索文件时,模糊匹配似乎可以对当前项目中的所有文件进行操作。 Unfortunately, this includes a number of files from build and vendor directories. 不幸的是,其中包括来自构建目录和供应商目录的许多文件。 So, for instance, if I want to search for all JavaScript files and do + O and type .js in, the file and symbol results include around 1500 hits and all of them except the two ones are complete noise. 因此,例如,如果我要搜索所有JavaScript文件并执行 + O,然后输入.js ,则文件和符号结果包括大约1500次匹配,除两个匹配之外,所有匹配均为完全干扰。

Is there a way to specify certain directories to be ignored for purpose of search? 有没有一种方法可以指定出于搜索目的而忽略的某些目录?


#1楼

参考:https://stackoom.com/question/21kyu/选择在VS-Code中搜索期间要忽略的文件夹


#2楼

This answer is outdated 这个答案已经过时了

If these are folders you want to ignore in a certain workspace, you can go to: 如果这些是您要在特定工作空间中忽略的文件夹,则可以转到:

AppMenu > Preferences > Workspace Settings

Otherwise, if you want these folders to be ignored in all your workspaces, go to: 否则,如果要在所有工作空间中忽略这些文件夹,请转到:

AppMenu > Preferences > User Settings

and add the following to your configuration: 并将以下内容添加到您的配置中:

//-------- Search configuration --------

// The folders to exclude when doing a full text search in the workspace.
"search.excludeFolders": [
    ".git",
    "node_modules",
    "bower_components",
    "path/to/other/folder/to/exclude"
],

The difference between workspace and user settings is explained in the customization docs 定制文档中说明工作空间和用户设置之间的区别


#3楼

These preferences appear to have changed since @alex-dima's answer. 自@ alex-dima回答以来,这些首选项似乎已更改。

Changing settings 变更设定

From menu choose: Preferences -> Settings -> User/Workspace Settings. 从菜单中选择:首选项->设置->用户/工作区设置。 Filter default settings to search . 过滤默认设置进行search

You can modify the search.exclude setting (copy from default setting to your user or workspace settings). 您可以修改search.exclude设置(从默认设置复制到用户或工作空间设置)。 That will apply only to searches. 这仅适用于搜索。 Note that settings from files.exclude will be automatically applied. 请注意, files.exclude中的设置将被自动应用。

If the settings don't work : 如果设置不起作用

  1. Make sure you dind't turn the search exclusion off. 确保您没有关闭搜索排除功能。 In the search area, expand the "files to exclude" input box and make sure that the gear icon is selected. 在搜索区域中,展开“要排除的文件”输入框,并确保选择了齿轮图标。

  2. You might also need to Clear Editor History (See: https://github.com/Microsoft/vscode/issues/6502 ). 您可能还需要清除编辑器历史记录(请参阅: https : //github.com/Microsoft/vscode/issues/6502 )。

Example settings 设定示例

For example, I am developing an EmberJS application which saves thousands of files under the tmp directory. 例如,我正在开发一个EmberJS应用程序,该应用程序将数千个文件保存在tmp目录下。

If you select WORKSPACE SETTINGS on the right side of the search field, the search exclusion will only be applied to this particular project. 如果在搜索字段的右侧选择“ WORKSPACE SETTINGS ”,则搜索排除项将仅应用于此特定项目。 And a corresponding .vscode folder will be added to the root folder containing settings.json . 相应的.vscode文件夹将被添加到包含settings.json的根文件夹中。

This is my example settings: 这是我的示例设置:

{
    // ...
    "search.exclude": {
        "**/.git": true,
        "**/node_modules": true,
        "**/bower_components": true,
        "**/tmp": true
    },
    // ...
}

Note : Include a ** at the beginning of any search exclusion to cover the search term over any folders and sub-folders. 注意 :在所有搜索排除项的开头都包括一个**,以覆盖所有文件夹和子文件夹中的搜索词。

Picture of search before updating settings : 更新设置前的搜索图片

Before updating the settings the search results are a mess. 在更新设置之前,搜索结果是一团糟。

更新设置之前的搜索图片

Picture of search after updating settings: 更新设置后的搜索图片:

After updating the settings the search results are exactly what I want. 更新设置后,搜索结果正是我想要的。

更新设置后的搜索图片。


#4楼

If I understand correctly you want to exclude files from the vscode fuzzy finder. 如果我理解正确,则想从vscode模糊查找器中排除文件。 If that is the case, I am guessing the above answers are for older versions of vscode. 如果是这样,我想上面的答案是针对旧版本的vscode。 What worked for me is adding: 对我有用的是添加:

"files.exclude": {
    "**/directory-you-want-to-exclude": true,
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true
}

to my settings.json . 到我的settings.json This file can be opened through File > Preferences > Settings 可以通过File > Preferences > Settings打开此文件


#5楼

After you setup the search.exclude and file.exclude mentioned on the previous answers, run the command "Clear Editor History" (Use the Command Palette to do that - CTRL + SHIFT + P). 设置先前答案中提到的search.exclude和file.exclude之后,运行命令“清除编辑器历史记录”(使用命令面板执行此操作-CTRL + SHIFT + P)。

Only after that the excluded files will not appear on your quick open menu. 仅在此之后,排除的文件将不会出现在快速打开菜单上。

Update: You can run the command "Clear Command History" too. 更新:您也可以运行命令“清除命令历史记录”。 I forgot about that. 我忘记了。


#6楼

Make sure the 'Use Exclude Settings and Ignore Files' cog is selected 确保已选中“使用排除设置并忽略文件”齿轮 在此处输入图片说明

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值