如何从Visual Studio代码"浏览"选项卡中排除目录?

And*_*rey 227 visual-studio-code

我正在尝试在Visual Studio代码中的"浏览"选项卡上排除多个文件夹.为此,我在项目的根目录中添加了以下jsconfig.json:

{
    "compilerOptions": {
        "target": "ES6"
    },
    "exclude": [
        "node_modules"
    ]
}
Run Code Online (Sandbox Code Playgroud)

但是"node_modules"文件夹仍然在目录树中可见.我究竟做错了什么?还有其他选择吗?

Wos*_*osi 411

使用files.exclude:

  • 转到文件 - >首选项 - >设置(或在Mac 代码 - >首选项 - >设置)
  • 选择workspace settings标签
  • 将此代码添加到settings.json右侧显示的文件中:

    // Place your settings in this file to overwrite default and user settings.
    
    {
        "files.exclude": {
            "**/.git": true,         // this is a default value
            "**/.DS_Store": true,    // this is a default value
    
            "**/node_modules": true, // this excludes all folders 
                                     // named "node_modules" from 
                                     // the explore tree
    
            // alternative version
            "node_modules": true    // this excludes the folder 
                                    // only from the root of
                                    // your workspace 
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)

如果选择" 文件" - >"首选项" - >"用户设置",则可以为当前用户全局配置排除文件夹.

  • 就好像有人想知道的那样:尾部斜线并没有帮助(也没有伤害)仅将排除限制为文件夹.ie`"**/BACKUP /":true`和没有最后一个斜线一样好/坏. (8认同)
  • 值得注意的是,在当前版本的Code(1.28.2)中,“ files.exclude”键位于“ code-workspace”文件的“ settings”键内部。 (5认同)
  • 继承在这里如何运作?我是否必须列出*所有*排除项或仅列出用户设置中未列出的项? (2认同)

Dre*_*kes 76

在较新版本的VS Code中,您可以导航到设置(Ctrl+ ,),并确保选择右上角的" 工作区设置".

在此输入图像描述

然后添加一个files.exclude选项以指定要排除的模式.

search.exclude如果您只想从搜索结果中排除文件,而不是从文件夹资源管理器中排除文件,也可以添加.

  • 从搜索中排除,同时仍然可以浏览资源管理器中的文件 - 正是我需要的,谢谢! (7认同)
  • 我将`files.exclude`放在`settings:{...}`里面,当它应用于*workspace settings*([.code-workspace]时(https://code.visualstudio.com/docs/editor/)多根工作空间)文件)否则它抱怨该属性未知的行.有一个_third_"文件夹设置"选项卡(.vscode/settings.json),它在最外面的大括号中工作. (3认同)

tot*_*dli 25

tl; dr

  1. Ctrl+ Shift+P
  2. 键入“工作空间设置”。
  3. 通过GUI或在中更改排除设置settings.json

GUI方式

  1. 在搜索栏中键入“排除”。
  2. 点击“添加模式”按钮。 在VS Code设置中添加排除模式

编码方式

  1. 点击右上角的小{}图标以打开settings.json单击方括号图标以打开settings.json
  2. 将排除的文件夹添加到中files.exclude。还要检查一下search.excludefiles.watcherExclude因为它们可能也很有用。此代码段包含其说明和默认值:

    {
      // Configure glob patterns for excluding files and folders. For example, the files explorer decides which files and folders to show or hide based on this setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
      "files.exclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/CVS": true,
        "**/.DS_Store": true
      },
      // Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the `files.exclude` setting. Read more about glob patterns [here](https://code.visualstudio.com/docs/editor/codebasics#_advanced-search-options).
      "search.exclude": {
        "**/node_modules": true,
        "**/bower_components": true
      },
      // Configure glob patterns of file paths to exclude from file watching. Patterns must match on absolute paths (i.e. prefix with ** or the full path to match properly). Changing this setting requires a restart. When you experience Code consuming lots of cpu time on startup, you can exclude large folders to reduce the initial load.
      "files.watcherExclude": {
        "**/.git/objects/**": true,
        "**/.git/subtree-cache/**": true,
        "**/node_modules/*/**": true
      }
    }
    
    Run Code Online (Sandbox Code Playgroud)

有关其他设置的更多详细信息,请参见官方settings.json参考


Nis*_*isd 6

在Visual Studio版本1.28中,"files.exclude"必须将代码放在settings节点内。

生成的工作空间文件如下所示:

{
    "settings": {
        "files.exclude": {
            "**/node_modules": true
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Jer*_*yal 6

这个资源管理器排除扩展正是可以做到这一点。https://marketplace.visualstudio.com/items?itemName=RedVanWorkshop.explorer-exclude-vscode-extension

它添加了一个隐藏当前文件夹/文件的选项到右键菜单。它还在资源管理器菜单中添加了一个垂直选项卡“隐藏项目”,您可以在其中查看当前隐藏的文件和文件夹,并可以轻松切换它们。


在此输入图像描述


归档时间:

查看次数:

101725 次

最近记录:

7 年 前