如何在 Sublime Text 中自定义文件类型与语法关联?

发布于 2024-12-14 17:18:58 字数 88 浏览 0 评论 0原文

我希望 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

感性 2024-12-21 17:19:07

我知道这个话题现在已经很老了,但让我陈述一种新方法,有些人可能会觉得这很容易理解和执行。

打开 Sublime Text(确保您的 Sublime Text 中已安装Package Control 已安装并准备就绪 ):

  1. Ctrl+Shift+P(对于 MacOS 用户则为 Cmd+Shift+P
  2. 输入“PRV”(包资源查看器),选择以 结尾的那个:打开Resource
  3. 输入“SCALA”/“scala”并按 Enter
  4. 输入 Scala.sublime-syntax 并按 Enter,然后按 Esc 关闭
    打开列表
  5. 现在在 Scala.sublime-syntax 中转到 file_extensions: 部分并添加文件扩展名 sbt(例如 - sbt) 在该部分的末尾
  6. 保存并关闭文件并重新启动 Sublime Text,您现在将拥有
    自定义 .sbt 扩展的 Scala 语法突出显示。可以对任何文件类型执行相同的步骤,例如 XMLPHPHTMLJS 等。

非常容易跟着吧?

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):

  1. Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
  2. Type "PRV"(Package Resource Viewer), select the one ending with :Open Resource
  3. Type "SCALA"/"scala" and press Enter
  4. Type Scala.sublime-syntax and press Enter and press Esc to close the
    open list
  5. Now in Scala.sublime-syntax goto the section file_extensions: and add your file extension sbt(like - sbt) in the end of that section
  6. Save and close the file and restart Sublime Text, you'll now have
    Scala syntax highlighting for your custom .sbt extension. Same steps can be done with any file type like XML, PHP, HTML, JS etc.

Pretty easy to follow, right ?

不顾 2024-12-21 17:19:06

有一个快速的方法来设置语法:
Ctrl+Shift+P,然后在输入框中输入

ss + (要设置哪种类型)

例如: ss html +Enter

ss 表示“设置语法”,

它比选中菜单的复选框要快。

There is a quick method to set the syntax:
Ctrl+Shift+P,then type in the input box

ss + (which type you want set)

eg: ss html +Enter

and ss means "set syntax"

it is really quicker than check in the menu's checkbox.

栩栩如生 2024-12-21 17:19:05

有一个名为 ApplySyntax(以前称为 DetectSyntax)的优秀插件,它为文件语法匹配提供了某些其他细节。允许正则表达式等。

There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.

撩人痒 2024-12-21 17:19:04

对于 ST3

$language = "language u Wish"

如果存在,打开 ~/.config/sublime-text-3/Packages/User/*$language*.sublime-settings

否则就创建它。

并设置

{
    "extensions":
    [
        "*yourextension*"
    ]
}

这种方式允许您启用复合扩展的语法(例如 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

{
    "extensions":
    [
        "*yourextension*"
    ]
}

This way allows you to enable syntax for composite extensions (e.g. sql.mustache, js.php, etc ... )

感情洁癖 2024-12-21 17:19:03

我将自定义更改放入用户包中:

*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage

这也意味着它采用 JSON 格式:

{
  "extensions":
  [
    "sbt"
  ]
}

这与菜单项添加它的位置相同

View -> Syntax -> Open all with current extension as ...

(如果文件不存在,则创建文件)。

I put my customized changes in the User package:

*nix: ~/.config/sublime-text-2/Packages/User/Scala.tmLanguage
*Windows: %APPDATA%\Sublime Text 2\Packages\User\Scala.tmLanguage

Which also means it's in JSON format:

{
  "extensions":
  [
    "sbt"
  ]
}

This is the same place the

View -> Syntax -> Open all with current extension as ...

menu item adds it (creating the file if it doesn't exist).

じ违心 2024-12-21 17:19:02

我找到了答案(通过进一步检查 Sublime 2 配置文件结构):

我要打开

~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage

并编辑它以添加 sbt (我想要作为 Scala 代码文件打开的文件的扩展名)到 fileTypes 键之后的数组:

<dict>
  <key>bundleUUID</key>
  <string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
  <key>fileTypes</key>
  <array>
    <string>scala</string>
    <string>sbt</string>
  <array>
  ...

PS:可能有更好的方法,比如放置我的自定义项的正确位置(而不是修改包本身),我仍然想知道。

I've found the answer (by further examining the Sublime 2 config files structure):

I was to open

~/.config/sublime-text-2/Packages/Scala/Scala.tmLanguage

And edit it to add sbt (the extension of files I want to be opened as Scala code files) to the array after the fileTypes key:

<dict>
  <key>bundleUUID</key>
  <string>452017E8-0065-49EF-AB9D-7849B27D9367</string>
  <key>fileTypes</key>
  <array>
    <string>scala</string>
    <string>sbt</string>
  <array>
  ...

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.

何以笙箫默 2024-12-21 17:19:01

在 Sublime Text 中(在 v2.x 和 v3.x 中均得到确认)有一个菜单命令:

查看->语法->打开所有当前扩展名为...

In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:

View -> Syntax -> Open all with current extension as ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文