如何在 Sublime Text 中从索引中排除文件夹,同时仍将其显示在侧边栏中?

问题描述 投票:0回答:5

对于具有许多依赖项的大型项目,例如在

node_modules/
文件夹中,我注意到由于 Sublime 索引了文件夹中的所有文件,CPU 经常出现峰值。

我知道我可以使用

folder_exclude_patterns
设置隐藏文件和文件夹,但我仍然希望该文件夹在侧边栏中可见。

我怎样才能保留例如

node_modules/
在侧边栏中,但将其排除在索引之外?

sublimetext2 sublimetext3 sublimetext
5个回答
202
投票

要将文件从索引中排除但将其保留在侧边栏中,请使用“用户设置”中的

binary_file_patterns
设置,例如:

"binary_file_patterns": [
  "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds",
  "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",
  "node_modules/**",
  "bower_components/**"
]

确保从您的

Settings - Default
首选项中复制值(此处显示为
"*.jpg"
等),否则您将开始索引二进制文件。


40
投票

您可以更改您的个人设置,在

Preferences -> Settings - User
中添加:

{
    "folder_exclude_patterns":
    [
        ".svn", ".git", ".hg", "CVS",
        "node_modules",
    ],
}

14
投票

Sublime Text 3 现在提供了一种从索引中排除文件和文件夹,同时将它们保留在侧边栏中的方法:

  "index_exclude_patterns": [
    "*.log",
    "node_modules/*"
  ]

在我的项目中,应用更改后,我观察到索引状态菜单有以下改进:

之前:

index "MyApp" collated in 0.70s from 73934 files
index "MyApp" is using 15167488 bytes for 54234 symbols across 1357673 locations

之后:

index "MyApp" collated in 0.00s from 137 files
index "MyApp" is using 61440 bytes for 730 symbols across 4763 locations

6
投票

不适用于 ST3(内部版本 3126)。

您可以在侧边栏中显示节点模块文件夹并隐藏其中的文件:

"file_exclude_patterns":
[
    ...,
    "node_modules/**"
]

如果您想隐藏每个节点模块的子文件夹:

"folder_exclude_patterns":
[
    "node_modules/*/**"
]

node_modules 内的所有文件都将从搜索中删除,但每个 node_module 子文件夹在侧边栏中仍然可见。


0
投票

我认为

binary_file_patterns
不起作用,因为我习惯右键单击顶级文件夹并选择“在文件夹中查找”。
folder_exclude_patterns
可以使用此功能,但
binary_file_patterns
仍然搜索所有内容 - 因为“位置”字段会覆盖设置。

因此,您可以使用菜单选项“查找”>“在文件中查找”,或者右键单击您的顶级文件夹,选择“在文件夹中查找”,然后删除“位置”字段中的文本,以便显示占位符文本“打开文件并文件夹”。

显然你仍然需要将其添加到首选项/设置中:

    "binary_file_patterns": [
      "node_modules/",
    ],
© www.soinside.com 2019 - 2024. All rights reserved.