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?
-
6It's a duplicate of: http://stackoverflow.com/q/7574502/1346682 – Nicolas Malbran Oct 14 '14 at 13:19
-
Possible duplicate of [Set default syntax to different filetype in Sublime Text 2](https://stackoverflow.com/questions/7574502/set-default-syntax-to-different-filetype-in-sublime-text-2) – Sean the Bean Aug 22 '17 at 18:36
7 Answers
In Sublime Text (confirmed in both v2.x and v3.x) there is a menu command:
View -> Syntax -> Open all with current extension as ...
-
25do you have any idea how this is reflected in the sublime text config files? I'm trying to achieve this with an automated chef recipe and I can't figure out what to set in the settings JSON. – brad Nov 09 '13 at 23:18
-
14@brad Open syntax specific settings (Scala.sublime-settings in Users folder), and add to them: { "extensions": ["scala", "sbt"]} – omittones Sep 10 '14 at 09:46
-
1Yet another command misteriously absent from the command palette (ctrl/cmd-shift-P) – Tobia Dec 18 '14 at 15:49
-
5Also doesn't work as expected for filenames with double extension. Editing the `*.sublime-settings` *does* work. – MM. Dec 24 '14 at 12:19
-
11How do you set a default syntax for files opened that have no extension? – cavalcade Feb 27 '15 at 23:50
-
Finally! How annoying I couldnt find this until now, had been fiddling around with an extension as suggested in another answer. – nights Nov 26 '16 at 05:43
-
1And what do you do when this whole menu is greyed out / lists everything but is entirely unselectable? – frumbert Dec 14 '16 at 05:24
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.

- 63,011
- 101
- 250
- 382
-
2it's now in ```/Library/Application Support/Sublime Text 2/Packages/Scala/Scala.tmLanguage``` – Guillaume Massé Aug 01 '12 at 04:28
-
2I think is the user library rather than the system library: `~/Library/Application Support/Sublime Text 2/Packages/Scala/Scala.tmLanguage` – seren Apr 23 '13 at 17:55
-
4@Eric, you should read more careful.. It opens all files with that specific extension with the specified syntax. Most of the time, this is what you want. – Vincent Ketelaars Nov 08 '13 at 19:13
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).

- 762
- 8
- 10
-
2Note that this is the only method (at least in ST2) that allows to set specific syntax for files with double extensions (for example, `whatever.twig.html`), as the menu method only takes the last one! – MM. Dec 24 '14 at 12:17
-
1I found this works with Sublime Text 3. I used `View -> Syntax -> Open all with current extension as ...` to create the language file `Markdown.sublime-settings` in `~/Library/Application Support/Sublime Text 3/Packages/User/`, and then edited this file to add extra file extensions. – Jake Rayson Apr 24 '17 at 08:30
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 ... )

- 4,555
- 31
- 31
- 45

- 733
- 5
- 21
-
4So to associate .js.php files with JavaScript, I should create a file called Javascript.sublime-settings filled with `{ "extensions": [ "js.php" ] }` ? – Austin Schmidt Jan 18 '17 at 17:41
-
Yes if the file not exists, if already exists just add the extension you desire on "extensions" array. – xpeiro Jan 19 '17 at 11:22
-
ST now has a menu item for this: `Settings` > `Settings -- Syntax Specific`. – General Grievance Jul 16 '21 at 22:36
There's an excellent plugin called ApplySyntax (previously DetectSyntax) that provides certain other niceties for file-syntax matching. allows regex expressions etc.

- 7,130
- 12
- 56
- 72
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.

- 1,414
- 3
- 16
- 20

- 453
- 4
- 9
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):
- Ctrl+Shift+P(or Cmd+Shift+P for MacOS guys)
- Type "PRV"(Package Resource Viewer), select the one ending with
:Open Resource
- Type "SCALA"/"scala" and press Enter
- Type
Scala.sublime-syntax
and press Enter and press Esc to close the open list - Now in
Scala.sublime-syntax
goto the sectionfile_extensions:
and add your file extensionsbt
(like- sbt
) in the end of that section - 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 likeXML
,PHP
,HTML
,JS
etc.
Pretty easy to follow, right ?

- 1,893
- 2
- 27
- 62