Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default syntax to different filetype in Sublime Text 2

How do I set a default filetype for a certain file extension in Sublime Text 2? Specifically I want to have *.cfg files default to having Ini syntax highlighting but I cannot seem to figure out how I could create this custom setting.

like image 655
keiththomps Avatar asked Sep 27 '11 19:09

keiththomps


People also ask

How to set syntax in Sublime Text 3?

To enable Syntax Highlighting click on “View” in the top bar, then hover your mouse over “Syntax”, and select your programming language from the list. Alternatively, if you save a document with a supported file extension, Sublime Text 3 will automatically apply the Syntax Highlighting for that language.

How do I change a file in Sublime?

You can manually change file type editing preferences using the SUBLIME-OPTIONS file. There is a User File Type. sublime-options file and a Default File Type. sublime-options file, which are both located in the Packages/​Default directory.

How do I change the default save location in Sublime Text?

You can view all the default settings files that ship with Sublime by going to View Package File and then typing Default/. sublime-settings . In addition to that packages & plugins can have their own custom settings that they apply depending on what the package/plugin in question is doing.


2 Answers

In the current version of Sublime Text 2 (Build: 2139), you can set the syntax for all files of a certain file extension using an option in the menu bar. Open a file with the extension you want to set a default for and navigate through the following menus: View -> Syntax -> Open all with current extension as... ->[your syntax choice].

Updated 2012-06-28: Recent builds of Sublime Text 2 (at least since Build 2181) have allowed the syntax to be set by clicking the current syntax type in the lower right corner of the window. This will open the syntax selection menu with the option to Open all with current extension as... at the top of the menu.

Updated 2016-04-19: As of now, this also works for Sublime Text 3.

like image 53
Colin R Avatar answered Oct 06 '22 16:10

Colin R


Go to a Packages/User, create (or edit) a .sublime-settings file named after the Syntax where you want to add the extensions, Ini.sublime-settings in your case, then write there something like this:

{     "extensions":["cfg"] } 

And then restart Sublime Text

like image 41
kizu Avatar answered Oct 06 '22 16:10

kizu