欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何在Visual Studio代码中隐藏侧栏中的某些文件?

程序员文章站 2022-05-23 23:19:50
...

本文翻译自:How do I hide certain files from the sidebar in Visual Studio Code?

Using Microsoft's Visual Studio Code, how do I hide certain files and file patterns from appearing in the sidebar? 使用Microsoft的Visual Studio代码,如何隐藏侧边栏中显示的某些文件和文件模式?

I want to hide .meta and .git style files 我想隐藏.meta.git样式文件


#1楼

参考:https://stackoom.com/question/22Soq/如何在Visual-Studio代码中隐藏侧栏中的某些文件


#2楼

You can configure patterns to hide files and folders from the explorer and searches. 您可以配置模式以从资源管理器和搜索中隐藏文件和文件夹。

  1. Open VS User Settings (Main menu: File > Preferences > Settings). 打开VS用户设置(主菜单:文件>首选项>设置)。 This will open the setting screen. 这将打开设置屏幕。
  2. Search for files:exclude in the search at the top. 搜索文件:在顶部的搜索中排除。
  3. Configure the User Setting with new glob patterns as needed. 根据需要使用新的glob模式配置用户设置。 In this case add this pattern node_modules/ then click OK. 在这种情况下,添加此模式node_modules/然后单击“确定”。 The pattern syntax is powerful. 模式语法很强大。 You can find pattern matching details under the Search Across Files topic . 您可以在“ 搜索跨文件”主题下找到模式匹配详细信息。

When you are done it should look something like this: 当你完成它应该看起来像这样: 如何在Visual Studio代码中隐藏侧栏中的某些文件?

If you want to directly edit the settings file: For example to hide a top level node_modules folder in your workspace: 如果要直接编辑设置文件:例如,要隐藏工作区中的*node_modules文件夹:

"files.exclude": {
    "node_modules/": true
}

To hide all files that start with ._ such as ._.DS_Store files found on OSX: 要隐藏所有以._开头的文件,例如在OSX上找到的._。DS_Store文件:

"files.exclude": {
    "**/._*": true
}

You also have the ability to change Workspace Settings (Main menu: File > Preferences > Workspace Settings). 您还可以更改工作区设置(主菜单:文件>首选项>工作区设置)。 Workspace settings will create a .vscode/settings.json file in your current workspace and will only be applied to that workspace. 工作区设置将在当前工作空间中创建.vscode/settings.json文件,并且仅应用于该工作空间。 User Settings will be applied globally to any instance of VS Code you open, but they won't override Workspace Settings if present. 用户设置将全局应用于您打开的任何VS代码实例,但如果存在,它们将不会覆盖工作区设置。 Read more on customizing User and Workspace Settings . 阅读有关自定义用户和工作区设置的更多信息


#3楼

Sometimes you just want to hide certain file types for a specific project. 有时您只想隐藏特定项目的某些文件类型。 In that case, you can create a folder in your project folder called .vscode and create the settings.json file in there, (ie .vscode/settings.json ). 在这种情况下,您可以在项目文件夹中创建一个名为.vscode的文件夹,并在其中创建settings.json文件(即.vscode/settings.json )。 All settings within that file will affect your current workspace only. 该文件中的所有设置都只会影响您当前的工作区。

For example, in a TypeScript project, this is what I have used: 例如,在TypeScript项目中,这是我使用的:

// Workspace settings
{
    // The following will hide the js and map files in the editor
    "files.exclude": {
        "**/*.js": true,
        "**/*.map": true
    }
}

#4楼

I would also like to recommend vscode extension Peep , which allows you to toggle hide on the excluded files in your projects settings.json. 我还想推荐使用vscode扩展Peep ,它允许您在项目settings.json中的被排除文件上切换隐藏。

Hit F1 for vscode command line (command palette), then 然后按F1键查看vscode命令行(命令调色板)

ext install [enter] peep [enter]

You can bind "extension.peepToggle" to a key like Ctrl+Shift+P (same as F1 by default) for easy toggling. 您可以将“extension.peepToggle”绑定到一个键,如Ctrl + Shift + P(默认情况下与F1相同),以便轻松切换。 Hit Ctrl+K Ctrl+S for key bindings, enter peep , select Peep Toggle and add your binding. 按Ctrl + K Ctrl + S进行键绑定,输入peep ,选择Peep Toggle并添加绑定。


#5楼

For .meta files while using Unity3D, I found the best pattern for hiding is: 对于使用Unity3D时的.meta文件,我发现隐藏的最佳模式是:

"files.exclude": {
  "*/**/**.meta": true
}

This captures all folders and subfolders, and will pick up foo.cs.meta in addition to foo.meta 这捕获所有文件夹和子文件夹,并会拿起foo.cs.meta除了foo.meta


#6楼

The " Make Hidden " extension works great! Make Hidden ”扩展功能非常棒!

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. 通过启用允许您轻松执行隐藏/显示操作的上下文菜单,使用视图窗格浏览器查看隐藏项目以及保存工作区以在批量隐藏项目之间快速切换的功能,“隐藏”可以更好地控制项目目录。