Sublime Text 特定子目录下文件的不同语法 [英] Sublime Text different syntax for files under a specific subdirectory
问题描述
有没有办法让 Sublime Text 对特定目录树中的文件使用不同的语法高亮插件?
Is there a way to make Sublime Text use a different syntax hilighting plugin for files inside a specific directory tree?
例如默认情况下,我想对 .js 文件使用默认的 Javascript 文件类型,但对于 ~/Unity/文件夹下的文件,我想使用 Unity3d-Javascript 文件类型.
E.g. By default I want to use the default Javascript file type for .js files, but for files under ~/Unity/ folder I want to use Unity3d-Javascript file type.
推荐答案
查看ApplySyntax
包.这是一个非常强大的插件,它允许您将任意正则表达式应用于文件的几个不同方面(文件名、内容、第一行、后缀等),然后根据它们分配语法.安装后,打开 Preferences ->包设置 ->应用语法 ->设置-默认
阅读所有笔记并查看正则表达式的设置方式.然后,打开 ... ->Settings-User
并添加您的自定义正则表达式.我还没有测试过这个,但是应该可以使用以下方法:
Check out the ApplySyntax
package. This is a very powerful plugin that allows you to apply arbitrary regexes to several different aspects of a file (file name, contents, first line, suffix, etc.) and then assign a syntax based on them. Once installed, open Preferences -> Package Settings -> ApplySyntax -> Settings-Default
to read all the notes and see how the regexes are set up. Then, open ... -> Settings-User
and add your custom regexes. I haven't tested this, but something along these lines should work:
{
"name": "Unity3D/UnityJavaScript",
"rules": [
{"file_name": ".*/Unity/.js$"}
]
}
祝你好运!
这篇关于Sublime Text 特定子目录下文件的不同语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!