如何在 Sublime Text 中自定义文件类型与语法关联?
我希望 Sublime 2 编辑器将 *.sbt 文件(以突出显示语法)视为 Scala 语言,与 *.scala 相同,但我找不到在哪里进行设置。你碰巧知道吗?
I'd like Sublime 2 editor to treat *.sbt files (to highlight syntax) as Scala language, same as *.scala, but I can't find where to set this up. Do you happen to know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我知道这个话题现在已经很老了,但让我陈述一种新方法,有些人可能会觉得这很容易理解和执行。
打开 Sublime Text(确保您的 Sublime Text 中已安装Package Control 已安装并准备就绪 ):
结尾的那个:打开Resource
Scala.sublime-syntax
并按 Enter,然后按 Esc 关闭打开列表
Scala.sublime-syntax
中转到file_extensions:
部分并添加文件扩展名sbt
(例如- sbt) 在该部分的末尾
自定义
.sbt
扩展的Scala
语法突出显示。可以对任何文件类型执行相同的步骤,例如XML
、PHP
、HTML
、JS
等。非常容易跟着吧?
I know this topic is old now, but let me state a new approach, some people might find this easy to understand and do.
Open Sublime Text(make sure you have Package Control installed and ready in your Sublime Text):
:Open Resource
Scala.sublime-syntax
and press Enter and press Esc to close theopen list
Scala.sublime-syntax
goto the sectionfile_extensions:
and add your file extensionsbt
(like- sbt
) in the end of that sectionScala
syntax highlighting for your custom.sbt
extension. Same steps can be done with any file type likeXML
,PHP
,HTML
,JS
etc.Pretty easy to follow, right ?
有一个快速的方法来设置语法:
Ctrl
+Shift
+P
,然后在输入框中输入例如: ss html +
Enter
和 ss 表示“设置语法”,
它比选中菜单的复选框要快。
There is a quick method to set the syntax:
Ctrl
+Shift
+P
,then type in the input boxeg: ss html +
Enter
and ss means "set syntax"
it is really quicker than check in the menu's checkbox.
有一个名为 ApplySyntax(以前称为 DetectSyntax)的优秀插件,它为文件语法匹配提供了某些其他细节。允许正则表达式等。
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.
对于 ST3
$language = "language u Wish"
如果存在,打开
~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
否则就创建它。
并设置
这种方式允许您启用复合扩展的语法(例如 sql.mustache、js.php 等...)
For ST3
$language = "language u wish"
If exists, open
~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings
else just create it.
And set
This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )
我将自定义更改放入用户包中:
这也意味着它采用 JSON 格式:
这与菜单项添加它的位置相同
(如果文件不存在,则创建文件)。
I put my customized changes in the User package:
Which also means it's in JSON format:
This is the same place the
menu item adds it (creating the file if it doesn't exist).
我找到了答案(通过进一步检查 Sublime 2 配置文件结构):
我要打开
并编辑它以添加 sbt (我想要作为 Scala 代码文件打开的文件的扩展名)到
fileTypes
键之后的数组:PS:可能有更好的方法,比如放置我的自定义项的正确位置(而不是修改包本身),我仍然想知道。
I've found the answer (by further examining the Sublime 2 config files structure):
I was to open
And edit it to add
sbt
(the extension of files I want to be opened as Scala code files) to the array after thefileTypes
key:PS: May there be a better way, something like a right place to put my customizations (insted of modifying packages themselves), I'd still like to know.
在 Sublime Text 中(在 v2.x 和 v3.x 中均得到确认)有一个菜单命令:
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command: