Alter Lagos
Alter Lagos

Reputation: 12550

Assign syntax to a file without an extension in Sublime Text 2

I have a file Guardfile in my rails project, but appears just in plain text, so each time is opened it must be assigned the ruby syntax to display it correctly.
I cannot use Open all with current extension as... because it doesn't have an extension, but I suppose I could assign a specific syntax to a file without an extension because files like Gemfile, Capfile or Rakefile are displaying correctly. How can I achieve this?

Upvotes: 10

Views: 2346

Answers (3)

Yam
Yam

Reputation: 793

For Sublime 3:

  1. Commmand + Shift + p: set syntax ruby
  2. Preference -> Settings - Syntax Specific
  3. Add syntax like following:

    {
        "extensions": [
            "Gemfile",
            "Gemfile.lock",
            "Podfile",
            "Podfile.lock",
            "Manifest.lock",
            "Fastfile_helper",
            "Fastfile",
            "Appfile"
        ]
    }
    

What really bad is that the syntax does not support fuzzy match, regex thing. This means you must list all the files.

Upvotes: 3

d_rail
d_rail

Reputation: 4119

Install facelessuser / ApplySyntax. It has a built in rule for Guardfiles. It is also good for other random files that should be set as a certain syntax. For example, here is one I set up for a random file that should have Bash syntax.

"syntaxes": [
  {
    "name": "ShellScript/Shell-Unix-Generic",
    "rules": [
      {"file_name": ".*random$"}
    ]
  }
]

The name value is the path to the tmLanguage file from Packages. ShellScript is the name of the Packages folder that the tmLanguage file is in. Shell-Unix-Generic is the tmLanguage file name.

Upvotes: 3

Hugo Corrá
Hugo Corrá

Reputation: 14799

Menu: Preferences -> Browser Packages

Then open the file Ruby\Ruby.tmLanguage

Look up for this block:

<array>
    <string>rb</string>
    <string>rbx</string>
    <string>rjs</string>
    <string>Rakefile</string>
    <string>rake</string>
    <string>cgi</string>
    <string>fcgi</string>
    <string>gemspec</string>
    <string>irbrc</string>
    <string>capfile</string>
    <string>Gemfile</string>
</array>

Add the new entry:

    <string>Guardfile</string>

Upvotes: 11

Related Questions