Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default syntax based on filename

Tags:

sublimetext2

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"?

like image 398
Matthew Avatar asked Aug 23 '12 22:08

Matthew


2 Answers

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.

like image 54
jamie young Avatar answered Oct 28 '22 19:10

jamie young


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"
    ]
}
like image 14
abhisekp Avatar answered Oct 28 '22 19:10

abhisekp