Sublime Text(下面简称ST) 是一个程序员必备的开发工具,这里就不做过多介绍了, 今天就介绍一下我们非常常用的项目设置和如如何将某些文件或者目录排除在st的项目或者搜索结果中的设置方法。
ST项目 Sublime Text Project
Sublime Text中的项目由两个文件组成:.sublime-project 项目文件,其中包含项目定义,以及.sublime-workspace 工作区文件,其中含有用户特定的数据,如打开的文件和对每个文件的修改。
一般来说,.sublime-project 项目文件将被签入版本控制,而.sublime-workspace 工作区文件则不会。
ST项目创建
ST的项目很简单,就是我们使用文件打开 打开的如果是一个文件夹,那么我们就可以在 Project --> save project as 这里保存当前打开的文件为一个ST项目。
ST项目设置 filter设置 Sublime Text Project setting
项目的设置是相对于文件夹的, 既我们的排除,或者包含的各种filter设置 如folder_exclude_patterns file_exclude_patterns binary_file_patterns等都是在folders这个下面的,这个和其他软件的项目设置有点不太一样!
ST项目设置格式:
.sublime-project 项目设置文件是一个JSON文件,支持三个顶级部分:
“folders”,用于包含的文件夹,文件以及文件查找的包含或者排除规则的设置
“settings”,用于项目设置覆盖,这里的设置是ST的项目特别设置,这里的设置会覆盖ST的用户设置。
“build_systems”,用于特定于项目的构建系统设置。
ST项目设置示例
.sublime-projec
{
"folders":
[
{
"path": "src",
"name":"XXX项目源码",
"folder_exclude_patterns":["#*",".git","node_modules"],
"binary_file_patterns":[
"#*",".git","vendor/*",
"*-lock.json","*.map",
"*.bk","*.sql_bak",
"*.gz","*.7z","*.tgz",
"*.woff","*.woff2"
],
"index_exclude_patterns":[
"#*",".git","vendor/*",
"*-lock.json","*.map",
"*.bk","*.sql_bak",
"*.gz","*.7z","*.tgz",
"*.woff","*.woff2"
],
},
{
"path": "docs",
"name": "项目文档",
"file_exclude_patterns": ["*.css"]
}
],
"settings":
{
"tab_size": 8
},
"build_systems":
[
{
"name": "List",
"shell_cmd": "ls -l"
}
]
}
示例ST项目设置图解
ST设置项详解
"folders"
The "folders" key contains an array of objects. Each object must have a "path" key, which may be relative to the project directory, or a fully qualified path.
Additional optional keys include:
"name" string
用于代替侧栏中文件夹名称的名称A name used in place of the folder name in the side bar
"file_include_patterns" array of strings
文件夹中要包含的文件模式。任何不符合这些模式的东西都将被排除在外。在“file_exclude_patterns”之前检查此项。Patterns of files to include from the folder. Anything not matching these patterns will be excluded. This is checked before "file_exclude_patterns".
"file_exclude_patterns" array of strings
要从文件夹中排除的文件模式。这将添加到同名的全局设置中。这是在“file_include_patterns”之后检查的。
Patterns of files to exclude from the folder. This is added to the global setting of the same name. This is checked after "file_include_patterns"."folder_include_patterns" array of strings
文件夹中要包含的文件夹模式。任何不符合这些模式的东西都将被排除在外。在“folder_exclude_patterns”之前检查此项。
Patterns of folders to include from the folder. Anything not matching these patterns will be excluded. This is checked before "folder_exclude_patterns".
"folder_exclude_patterns" array of strings
要从文件夹中排除的文件夹模式。这将添加到同名的全局设置中。这是在“folder_include_patters”之后检查的。
Patterns of folders to exclude from the folder. This is added to the global setting of the same name. This is checked after "folder_include_patterns".
"binary_file_patterns" array of strings
将文件模式视为二进制文件,因此在Goto Anything和Find in files中忽略。
Patterns of files to treat as binary files, and thus ignored in Goto Anything and Find in Files.
"index_include_patterns" array of strings
文件夹中要索引的文件模式。这将添加到同名的全局设置中。任何不符合这些模式的东西都将被排除在索引之外。在“index_exclude_patterns”之前检查此项。
Patterns of files to index in the folder. This is added to the global setting of the same name. Anything not matching these patterns will be excluded from the index. This is checked before "index_exclude_patterns".
"index_exclude_patterns" array of strings
文件夹中要从索引中排除的文件模式。这将添加到同名的全局设置中。这是在“index_include_patterns”之后检查的。
Patterns of files to excluding from indexing in the folder. This is added to the global setting of the same name. This is checked after "index_include_patterns".
"follow_symlinks" boolean
如果在构建文件夹树时应遵循符号链接。
从早期版本转换的项目在“文件夹”下可能有一个“mount_points”条目。如果你想使用排除模式,你需要更改为上述格式。
If symlinks should be followed when building the folder tree.
Converted projects from earlier versions may have a "mount_points" entry under "folders". If you wish to use the exclude patterns, you’ll need to change to the above format.
"settings" Key
Settings may be specified here using the "settings" key, and will override regular user settings. They will not, however, override syntax-specific settings.
Note that only settings in the category Editor Settings may be controlled by a project.
"build_systems" Key
"build_systems" specifies a list of inline Build Systems definitions. In addition to the regular build system settings, a "name" must be specified for each one. Build systems listed here will be available via the regular Tools ▶ Build Systems menu.
如何将某些文件或者目录排除在st的项目或者搜索结果中的设置方法 --文件夹查找 替换Filter规设置 Find in Folder <project filters>
在文件夹查找中的<project filters> 设置项既是将某些文件或者目录排除在st的项目或者搜索结果中的设置,对应的ST设置项目为 binary_file_patterns, 如下图所示:
参考文档ST项目设置官方文档https://www.sublimetext.com/docs/projects.html