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: stackoverflow.com/q/7574502/1346682– Nicolas MalbranOct 14, 2014 at 13:19
-
Possible duplicate of Set default syntax to different filetype in Sublime Text 2– Sean the BeanAug 22, 2017 at 18:36
6 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 ...
-
23do 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.– bradNov 9, 2013 at 23:18
-
13@brad Open syntax specific settings (Scala.sublime-settings in Users folder), and add to them: { "extensions": ["scala", "sbt"]} Sep 10, 2014 at 9:46
-
1Yet another command misteriously absent from the command palette (ctrl/cmd-shift-P)– TobiaDec 18, 2014 at 15:49
-
5Also doesn't work as expected for filenames with double extension. Editing the
*.sublime-settings
does work.– MM.Dec 24, 2014 at 12:19 -
10How do you set a default syntax for files opened that have no extension? Feb 27, 2015 at 23:50
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.
-
2it's now in
/Library/Application Support/Sublime Text 2/Packages/Scala/Scala.tmLanguage
Aug 1, 2012 at 4:28 -
2I think is the user library rather than the system library:
~/Library/Application Support/Sublime Text 2/Packages/Scala/Scala.tmLanguage
– serenApr 23, 2013 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. Nov 8, 2013 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).
-
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, 2014 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 fileMarkdown.sublime-settings
in~/Library/Application Support/Sublime Text 3/Packages/User/
, and then edited this file to add extra file extensions. Apr 24, 2017 at 8: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 ... )
-
3So to associate .js.php files with JavaScript, I should create a file called Javascript.sublime-settings filled with
{ "extensions": [ "js.php" ] }
? Jan 18, 2017 at 17:41 -
Yes if the file not exists, if already exists just add the extension you desire on "extensions" array.– xpeiroJan 19, 2017 at 11:22
-
ST now has a menu item for this:
Settings
>Settings -- Syntax Specific
. Jul 16, 2021 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.
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.