50

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

2 Answers 2

114
+50

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.

Sign up to request clarification or add additional context in comments.

2 Comments

The "Ruby" option is grayed out for me in that menu. :/
@SarahVessels Create a file with a .rb extension in the same project folder and Sublime will enable the Ruby option. Hope that helps.
14

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"
    ]
}

1 Comment

The settings file is Ruby.sublime-settings. This grants default Ruby settings for Vagrantfiles when they are opened.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.