如何从Sublime Text中的侧边栏中永久排除文件夹,并相对于打开的文件夹指定它? [英] How do I exclude a folder from the sidebar in Sublime Text permanently, specifying it relative to the open folder?
问题描述
我已经阅读了此相关问题(How do I exclude a folder from search in sublime text 3 permanently?),但我的问题不同,因为我只想指定打开文件夹根目录下的文件夹,而不是文件夹树中任何级别匹配的通用模式。
在Sublime Text 4中,我有一个通过文件打开的项目文件夹--&>打开文件夹...&q;。
假设我的文件夹布局如下:
mainapp
├── microapp
│ └── node_modules <== don't exclude this (keep it)
├── microapp2
│ └── node_modules <== don't exclude this (keep it)
├── index
├── node_modules <=== exclude this only
├── config
└── assets
我只想排除mainapp/node_modules
,而不是mainapp/microapp/node_modules
或mainapp/microapp2/node_modules
。我该怎么做?
我猜我需要在设置中指定"folder_exclude_patterns"
。
附注:我为什么需要这样做?
因为该文件夹中有太多的构建内容(随着构建的发生而不断变化),这实际上会导致Sublime文本冻结、锁定并变得不可用。
推荐答案
在Linux Ubuntu 18.04上测试。
通过纯粹的愚蠢的运气和坚持不懈的猜测,我找到了答案。//
显然是指";打开的文件夹根目录。
如果您想查看添加到Sublime官方文本文档和默认设置文件中的有关//
的信息,请支持我的open issue on it here。
更新
我找到了一些关于这方面的官方文档:https://www.sublimetext.com/docs/file_patterns.html。添加了//
功能,从Sublime Text 4:
然而,我的测试证明,如果模式以
//
开头,则将其作为项目根目录的相对路径进行比较[在版本4.0中添加]
//
实际上表示&路径&根,但定义如下。因此,我下面的例子仍然正确。
1.如果您通过文件--&>打开文件夹...&q;打开文件夹,请执行以下操作:
首选项-->;设置-->;将此"folder_exclude_patterns"
条目添加到您的用户设置JSON文件:
{
// other user settings here
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
// other user settings here
}
同样,//
表示打开的文件夹的根目录。
注意:更改上面的用户设置将全局应用于您的所有Sublime Text实例,这可能不是您想要的。因此,使用项目可能更好,如下所述:
2.如果打开文件夹并将其保存为项目的一部分,请执行以下操作:
项目-->;编辑项目-->;将此"folder_exclude_patterns"
条目添加到您的项目设置JSON文件:
{
"folders":
[
{
// path to an open folder in a project
"path": "/path/to/mainapp",
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
}
],
}
您可以在这里的官方项目设置文件示例(https://www.sublimetext.com/docs/projects.html)中看到,"folder_exclude_patterns"
条目必须在JSON设置文件中与"path"
条目处于同一级别。
我也是从@smhg's comment here学到这一点的。谢谢!
要在您的项目中打开另一个文件夹,请转到项目--&>将文件夹添加到项目...&q;。在项目中打开多个文件夹后,您必须根据需要添加"folder_exclude_patterns"
的多个条目,如下所示:
{
"folders":
[
{
// **absolute path** to open a folder in a project
"path": "/path/to/mainapp",
// exclude only the "mainapp/node_modules" dir
"folder_exclude_patterns": ["//node_modules"],
},
{
// or **relative path** to open another folder in the project;
// the path is relative to the location of the
// "project_name.sublime-project" project file itself
"path": "some_dir",
// exclude only the "some_dir/path/to/excluded_folder" dir
"folder_exclude_patterns": ["//path/to/excluded_folder"],
},
],
}
奖金:如何在崇高文本中创建项目:
要从打开的文件夹创建项目,步骤如下:
- 打开文件夹:文件--&>打开文件夹...
- 将其另存为项目的一部分:项目--&>将项目另存为...
- 现在您可以选择保存
project_name.sublime-project
文件的位置。这是您在转到上面的项目--&>;编辑项目时正在编辑的文件。要打开项目,请转到项目--&>打开项目...&q;。
- 现在您可以选择保存
另请参阅:
我打开的问题:https://github.com/sublimehq/sublime_text/issues/5234
我在崇高文本论坛上的评论:https://forum.sublimetext.com/t/a-way-to-specify-root-in-project-settings/7756/4?u=ercaguy
项目设置官方文档:https://www.sublimetext.com/docs/projects.html。这包括:
每个对象都必须有
"path"
项,它可以是相对于项目目录的项,也可以是完全限定的路径。How do I exclude a folder from search in sublime text 3 permanently?-说明如何从崇高文本中的侧栏中排除文件或文件夹,而不是从搜索中排除文件或文件夹,例如转到任何内容或在文件中查找。
这篇关于如何从Sublime Text中的侧边栏中永久排除文件夹,并相对于打开的文件夹指定它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!