This article was translated from: 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? How to set the default file type for a specific 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. Specifically, I want * .cfg files to have Ini syntax highlighting by default, but I seem to Can't figure out how to create this custom setting.
#1st Floor
Reference: https://stackoom.com/question/VmTO/ Set the default syntax to different file types in Sublime-Text-
#2nd Floor
You can turn on syntax highlighting based on the contents of the file. You can turn on syntax highlighting based on the contents of the file .
For example, my Makefiles regardless of their extension the first line as follows: For example, my Makefiles regardless of their extension, the first line is as follows :
#-*-Makefile-*- vim:syntax=make
This is typical practice for other editors such as vim. This is a typical practice for other editors such as vim .
HOWEVER, for the this to you you need to the Modify Work at The Makefile.tmLanguage
File. However, this, you need to modify the Makefile.tmLanguage
file.
Find the file (for Sublime Text 3 in Ubuntu) at: Find the file at the following location (for Sublime Text 3 in Ubuntu ):
/opt/sublime_text/Packages/Makefile.sublime-package
Note, that is really a zip file. Note, that is really a zip file . Copy it, rename with .zip at the end, and extract the Makefile.tmLanguage file from it. Copy it, finally rename it with .zip, and then extract the Makefile.tmLanguage file from it .
At The new new Edit
Makefile.tmLanguage
by Adding at The "firstLineMatch" at The Key and the After String "fileTypes" Section. By adding after "fileTypes" part "firstLineMatch" button and edit the new stringMakefile.tmLanguage
. In the example below, the last two lines are new (should be added by you). In the example below, the last two lines are new (should be added by you ). The<string>
section holds the regular expression, that will enable syntax highlighting for the files that match the first line. The<string>
section contains regular expressions that enable syntax highlighting for files that match the first line . This expression recognizes two patterns: "-*-Makefile-*-
" and "vim:syntax=make
". This expression recognizes two patterns: "-*-Makefile-*-
" and "vim:syntax=make
".... <key>fileTypes</key> <array> <string>GNUmakefile</string> <string>makefile</string> <string>Makefile</string> <string>OCamlMakefile</string> <string>make</string> </array> <key>firstLineMatch</key> <string>^#\\s*-\\*-Makefile-\\*-|^#.*\\s*vim:syntax=make</string>
Modified at The Place
Makefile.tmLanguage
in the User Settings at The Directory: The modifiedMakefile.tmLanguage
on the user settings directory:~/.config/sublime-text-3/Packages/User/Makefile.tmLanguage
All the files matching the first line rule should turn the syntax highlighting on when opened. All files that match the first line rule should turn on the syntax highlighting on opening.
#3rd floor
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: go to one Packages/User
, create (or edit) a .sublime-settings
file, and the file is based on you Hope to add the syntax name of the extension, in your case Ini.sublime-settings
, then write something like this:
{
"extensions":["cfg"]
}
And then restart Sublime Text
#4th floor
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. In Sublime Text 2: The current version (Build 2139), you You can use the options in the menu bar to set the syntax of all files with a specific file extension. A File Extension with at The Open you want to the SET A default for the Navigate through and at The following Menus: View -> Syntax -> Open all with current extension as... ->[your syntax choice]
. Open a file that contains the extension you want to set default values, and then browse to the following menu: 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. Update 2012-06-28: Sublime The latest version of Text 2 (at least since Build 2181) allows you to set the grammar by clicking the current grammar 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. This will open the syntax selection menu and the options selected at the top of the menu .Open all with current extension as...
Updated 2016-04-19: As of now, this also works for Sublime Text 3. Update 2016-04-19: As of now, this also applies to Sublime Text 3.
#5th Floor
In ST2 there's a package you can install called Default FileType which does just that. In ST2, you can install a package called Default FileType. More info on https://github.com/spadgos/sublime-DefaultFileType . For more information about https://github.com/spadgos/sublime-DefaultFileType .