【问题标题】:How do I exclude a folder from search in sublime text 3 permanently?如何从 sublime text 3 中的搜索中永久排除文件夹?
【发布时间】:2018-01-07 11:46:09
【问题描述】:

有没有办法在项目视图中始终忽略文件夹...。

我在一个 repo 中有多个应用程序,并且每个应用程序中都有“node_modules”

mainapp
├── microapp
│   └── node_modules
├── microapp2
│   └── node_modules
├── index
├── config
└── assets

当我在上述结构中的项目内部搜索时,我想从搜索中排除 node_modules 文件夹。

【问题讨论】:

  • 你试过使用folder_exclude_patterns吗?
  • 现在不行了

标签: search editor sublimetext3 sublimetext text-editor


【解决方案1】:

我为我的中型 Rub​​y on Rails 项目添加了 "node_modules/", "coverage/", "tmp/cache/"binary_file_patterns,以加快我痛苦的缓慢搜索:

"binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", 
                         "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip",  
                         "node_modules/", "coverage/", "tmp/cache/", "vendor/bundle/"],

之前,Find All In Files 大约需要 7 秒:

Searching 28526 files for "as records_with_errors"

之后,Find All In Files 耗时不到 1 秒:

Searching 1658 files for "as records_with_errors" 

我添加coverage 不是为了提高性能,而是为了防止出现多余、无用的搜索结果。


顺便说一句,我发现这个问题的大多数解决方案都集中在 folder_exclude_patterns 上,而忽略了 binary_file_patterns 可以指定文件夹模式,可能是由于它的名称和 Sublime 的默认设置。

使用 folder_exclude_patterns 不是 OP 正在寻找的干净解决方案。它从侧边栏中隐藏文件夹这一事实肯定会让你挑战自己的理智,当有一天你去寻找那些文件时,它们根本不存在。

这种担忧也适用于查找结果的抑制,当然,在阻止太多文件夹之前应该仔细权衡。只包含您积极想要抑制的文件夹/模式...不要包含您认为如果它们不会给您带来问题就不需要搜索的东西。

【讨论】:

  • 对我来说,这仍然会搜索 node_modules。有什么想法吗?
  • 你能从你的配置中支付那条线吗?
  • 当然,它是 "binary_file_patterns": [ ".jpg", ".jpeg", ".png", ".gif", “.ttf”、“.tga”、“.dds”、“.ico”、“.eot”、“.pdf” , ".swf", ".jar", ".zip", "node_modules/", "vendor/*", ".cache_loader/*" ],
  • 嗯......这似乎与我在当地得到的完全匹配。您能否确认它抑制了您的其他一些排除项的结果,例如“vendor/*”或“.pdf”?
  • 此方法仅适用于“在文件中查找”面板中的“位置”字段不包含文件夹的情况。如果该字段包含目录(例如,如果您在侧边栏中右键单击并选择“在文件夹中查找”),binary_file_patterns 将不起作用。这是问题所在:github.com/sublimehq/sublime_text/issues/959
【解决方案2】:

转到设置菜单并在用户的Preferences.sublime-settings 文件中,向名为folder_exclude_patterns 的json 添加一个新节点。在里面添加不想显示的文件夹(json数组格式)。

例子:

{
    // ... other settings
    "folder_exclude_patterns": ["node_modules", "another_folder"],
}

如果您想排除某些目录或文件而不将其从侧边栏中隐藏,您可以忽略上述解决方案和搜索栏Where 部分中的Add Exclude Filter。但是每次更改搜索目录时都必须指定它。

注意:您可能需要重新启动 Sublime Text 才能看到更改,正如 @Soferio 所述

【讨论】:

  • 这种方法的问题在于,它不仅将这些文件夹从搜索中排除,而且从侧边栏中排除,这并不总是可取的。我仍在寻找不会破坏侧边栏的可靠解决方案。
  • @IllyaMoskvin 我已经更新了答案以添加一些您想要的解决方案,但它不会是永久性的。或许可以通过一些第三方插件实现。
  • -*/node_modules/* 以前不起作用,但今晚它神奇地起作用了。 "folder_exclude_patterns" 从侧边栏中隐藏文件夹,但不从搜索中隐藏:/
  • 最后,真正有效并排除了大量不受欢迎的搜索结果的方法是按照@jacob 的建议插入-*/node_modules/*。我之前的搜索是大约 20.000 个文件,然后下降到大约 80 个。
  • "binary_file_patterns": ["**/node_modules/**"] 最终为我工作!
【解决方案3】:

这些是正确的解决方案,但是您必须重新启动 Sublime3 才能使更改的配置生效。不要只是关闭窗口,退出整个应用程序。

【讨论】:

    【解决方案4】:

    如果您转到“首选项”菜单,然后选择“设置”,它将打开一个包含所有设置及其默认值的 JSON 文件。该文件还用作设置含义的文档。其中两个在这里是相关的。这是 JSON 文件中的 sn-p;

    // folder_exclude_patterns and file_exclude_patterns control which files
    // are listed in folders on the side bar. These can also be set on a per-
    // project basis.
    "folder_exclude_patterns": [".svn", ".git", ".hg", "CVS"],
    "file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db", "*.sublime-workspace"],
    // These files will still show up in the side bar, but won't be included in
    // Goto Anything or Find in Files
    "binary_file_patterns": ["*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
    

    这里说folder_exclude_patterns 将其从侧边栏中隐藏,而binary_file_patterns 将其从搜索中隐藏。所以如果你想从两者中排除它,你可以打开用户设置文件(它会覆盖默认设置)并添加;

    {
        "folder_exclude_patterns": ["node_modules"],
        "binary_file_patterns": ["*/node_modules/*"]
    }
    

    请注意,两者是不同的,因为前者是文件夹模式,而后者是文件模式。

    【讨论】:

    • 这似乎是正确的答案,但对我来说它仍然搜索 node_modules/ 和 vendor/ 似乎,搜索的文件数是相同的。有什么想法吗?
    • 这对我有用,但只有在重新启动 sublime3 之后,所以不要放弃......!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-25
    • 2015-04-07
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2010-10-01
    • 2014-02-08
    相关资源
    最近更新 更多