How to customise file type to syntax associations in Sublime Text?

Syntax HighlightingSublimetext

Syntax Highlighting Problem Overview


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?

Syntax Highlighting Solutions


Solution 1 - Syntax Highlighting

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

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

Solution 2 - Syntax Highlighting

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.

Solution 3 - Syntax Highlighting

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

Solution 4 - Syntax Highlighting

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

Solution 5 - Syntax Highlighting

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

Solution 6 - Syntax Highlighting

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIvanView Question on Stackoverflow
Solution 1 - Syntax HighlightingTedGView Answer on Stackoverflow
Solution 2 - Syntax HighlightingIvanView Answer on Stackoverflow
Solution 3 - Syntax HighlightingsqueegeeView Answer on Stackoverflow
Solution 4 - Syntax HighlightingxpeiroView Answer on Stackoverflow
Solution 5 - Syntax HighlightingKaushik GopalView Answer on Stackoverflow
Solution 6 - Syntax HighlightingHello Wor1dView Answer on Stackoverflow