Changing default syntax based on filename

Sublimetext2

Sublimetext2 Problem Overview


In Sublime Text 2, I've seen ways of basing the syntax off of the extension. But what about a filename with no extension? For example, I often have a file called "Vagrantfile" which is in ruby, yet Sublime Text 2 always wants to start off in plain text. Is there a way to have it default to "ruby" for a file if it is called "Vagrantfile"?

Sublimetext2 Solutions


Solution 1 - Sublimetext2

With Sublime Text 2.0.1, build 2217, look in the lower right of the window, where it says "Plain Text" for the Vagrantfile that is open.

enter image description here

Click that and in the menu that opens, at the top, there will be an "Open all with current extension as ..." sub-menu. Go into that sub-menu and choose Ruby.

Even though the Vagrantfile has no extension, Sublime will remember this and open Vagrantfiles with the Ruby syntax as expected. This does not spread to all files with no extension.

Solution 2 - Sublimetext2

Add the following line to the Syntax Specific - User file in

Preferences > Setting - More > Syntax Specific - User

for permanent staying of the syntax for every Vagrantfile file.


{
	"extensions":
	[
		"Vagrantfile"
	]
}

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
QuestionMatthewView Question on Stackoverflow
Solution 1 - Sublimetext2jamie youngView Answer on Stackoverflow
Solution 2 - Sublimetext2abhisekpView Answer on Stackoverflow