关于vscode设置:如何在Visual Studio Code的侧栏中隐藏某些文件?

How do I hide certain files from the sidebar in Visual Studio Code?

使用Microsoft的Visual Studio代码,如何隐藏某些文件和文件模式以免它们出现在边栏中?

我想隐藏.meta.git样式文件


您可以配置模式以隐藏资源管理器和搜索中的文件和文件夹。

  • 打开" VS用户设置"(主菜单:"文件">"首选项">"设置")。这将打开设置屏幕。
  • 搜索文件:不包括在顶部搜索中。
  • 根据需要用新的glob模式配置用户设置。在这种情况下,请添加此模式node_modules/,然后单击"确定"。模式语法功能强大。您可以在"搜索整个文件"主题下找到模式匹配的详细信息。
  • 完成后,它应如下所示:
    enter image description here

    如果要直接编辑设置文件:
    例如,在工作区中隐藏顶级node_modules文件夹:

    1
    2
    3
    "files.exclude": {
       "node_modules/": true
    }

    要隐藏所有以._开头的文件,例如OSX上的._。DS_Store文件,请执行以下操作:

    1
    2
    3
    "files.exclude": {
       "**/._*": true
    }

    您还可以更改工作区设置(主菜单:文件>首选项>工作区设置)。工作区设置将在您当前的工作区中创建一个.vscode/settings.json文件,并将仅应用于该工作区。用户设置将全局应用于您打开的任何VS Code实例,但它们不会覆盖"工作区设置"(如果存在)。阅读有关自定义用户和工作区设置的更多信息。


    有时,您只想隐藏特定项目的某些文件类型。在这种情况下,您可以在项目文件夹中创建一个名为.vscode的文件夹,并在其中创建settings.json文件(即.vscode/settings.json)。该文件中的所有设置仅会影响您当前的工作空间。

    例如,在TypeScript项目中,这就是我所使用的:

    1
    2
    3
    4
    5
    6
    7
    8
    // Workspace settings
    {
        // The following will hide the js and map files in the editor
       "files.exclude": {
           "**/*.js": true,
           "**/*.map": true
        }
    }


    对于使用Unity3D时的.meta文件,我发现隐藏的最佳模式是:

    1
    2
    3
    "files.exclude": {
     "*/**/**.meta": true
    }

    这将捕获所有文件夹和子文件夹,并且除了foo.meta还将拾取foo.cs.meta


    "隐藏"扩展非常好!

    Make Hidden provides more control over your project's directory by enabling context menus that allow you to perform hide/show actions effortlessly, a view pane explorer to see hidden items and the ability to save workspaces to quickly toggle between bulk hidden items.


    我还想推荐vscode扩展名Peep,它允许您在项目settings.json中切换隐藏文件的隐藏。

    按下F1以获得vscode命令行(命令选项板),然后

    1
    ext install [enter] peep [enter]

    您可以将" extension.peepToggle"绑定到Ctrl + Shift + P之类的键(默认情况下与F1相同)以方便切换。按Ctrl + K Ctrl + S进行按键绑定,输入peep,选择"窥视切换"并添加您的绑定。


    开发人员完全不需要__pycache__文件夹和*.pyc文件。要从资源管理器视图中隐藏这些文件,我们需要为VSCode编辑settings.json。添加文件夹和文件,如下所示:

    1
    2
    3
    4
    5
    6
    7
    8
    "files.exclude": {
      ...
      ...
     "**/*.pyc": {"when":"$(basename).py"},
     "**/__pycache__": true,
      ...
      ...
    }


    如果您正在使用Angular 2+应用程序,并且像我一样喜欢一个干净的工作环境,请遵循@ omt66答案并将以下内容粘贴到settings.json文件中。
    我建议您在完成所有初始设置后执行此操作。

    注意:这实际上也会同时隐藏.vscode文件夹(带有settings.json)。 (如果您之后需要进行更改,请在本机文件浏览器/文本编辑器中打开)

    https://pastebin.com/X2NL6Vxb

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    {
       "files.exclude": {
           ".vscode":true,
           "node_modules/":true,
           "dist/":true,
           "e2e/":true,
           "*.json": true,
           "**/*.md": true,
           ".gitignore": true,
           "**/.gitkeep":true,
           ".editorconfig": true,
           "**/polyfills.ts": true,
           "**/main.ts": true,
           "**/tsconfig.app.json": true,
           "**/tsconfig.spec.json": true,
           "**/tslint.json": true,
           "**/karma.conf.js": true,
           "**/favicon.ico": true,
           "**/browserslist": true,
           "**/test.ts": true
        }
    }