Sublime Forum

How can i set the default syntax for files?

#1

I want to set the default html syntax for *.xtpl / *.tpl / etc.
How can i do this?

0 Likes

#2

still can’t find it :frowning:

0 Likes

#3

On OS X you can change the “fileTypes” dictionary in the ~/Library/Application Support/Sublime Text 2/Packages/HTML/HTML.tmLanguage file. Simply add a new entry for the file types you’re interested in:

   <key>fileTypes</key>
	<array>
		<string>html</string>
		<string>htm</string>
		<string>shtml</string>
		<string>xhtml</string>
		<string>phtml</string>
		<string>inc</string>
		<string>tmpl</string>
		<string>tpl</string>
		<string>ctp</string>
      <string>xtpl</string> <!-- added this line for *.xtpl support -->
	</array>

It’s probably a similar process on Windows and Linux, you just need to find where Sublime Text 2 stores its Packages.

0 Likes

#4

burksa, thank you very much!
In Win7 it file there - C:\Users{UserName}\AppData\Roaming\Sublime Text 2\Packages\HTML\HTML.tmLanguage
And in Sublime - Preferences -> Brose Packages…

0 Likes

#5

If you don’t want to change syntax files, you could try DetectSyntax [1] or do something similar.

[1] github.com/phillipkoebbe/DetectSyntax

0 Likes

#6

Alternatively, you can use the “View/Syntax/Open all with current Extension as…” menu

0 Likes

#7

I have the same question. I’m trying to get .ctp files automatically recognized as “HTML (PHP Cake)” and I have that option checked in the “Open all with current Extension as…” submenu, but every time I reopen one of those files, it reverts to the “PHP” syntax. I also have a DetectSyntax rule set up (see code below), but that doesn’t seem to do it either.

	{
		"name": "PHP",
		"rules": 
			{"file_name": ".*\\.(php|inc)$"},
			{"first_line": "^<\\?php"}
		]
	},
	{
		"name": "HTML (PHP Cake)",
		"rules": 
			{"file_name": ".*\\.(ctp|thtml)$"}
		]
	},
0 Likes

#8

[quote=“cgibby”]I have the same question. I’m trying to get .ctp files automatically recognized as “HTML (PHP Cake)” and I have that option checked in the “Open all with current Extension as…” submenu, but every time I reopen one of those files, it reverts to the “PHP” syntax. I also have a DetectSyntax rule set up (see code below), but that doesn’t seem to do it either.

{ "name": "PHP", "rules": {"file_name": ".*\\.(php|inc)$"}, {"first_line": "^<\\?php"} ] }, { "name": "HTML (PHP Cake)", "rules": {"file_name": ".*\\.(ctp|thtml)$"} ] }, [/quote]

Will you please create an issue [1] for this? Please paste your complete DetectSyntax.sublime-settings and a sample CTP file as gists and link to them in the issue. If you would also provide all pertinent information like platform, version, etc etc (anything that could be useful), I’d really appreciate it. I’ll dig in and see if I can figure out why DetectSyntax didn’t get the right syntax assigned.

[1] github.com/phillipkoebbe/DetectSyntax/issues

0 Likes

#9

Thank you very much ! :smiley:

0 Likes