Syntax detector for Sublime Text 2
Pull request Compare This branch is 24 commits ahead, 1 commit behind wzdf1982:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



If you find DetectSyntax helpful, please consider making a donation.

Click here to lend your support to: DetectSyntax and make a donation at !


DetectSyntax is a plugin for Sublime Text 2 that allows you to detect the syntax of files that might not otherwise be detected properly. For example, files with the .rb extension are usually Ruby files, but when they are found in a Rails project, they could be RSpec spec files, Cucumber step files, Ruby on Rails files (controllers, models, etc), or just plain Ruby files. This is actually the problem I was trying to solve when I started working on this plugin.


DetectSyntax can be installed in a variety of ways:

  • Through Package Control

    Open Package Control
    Select 'Install Package'
    Find and select 'DetectSyntax'

  • By cloning this repository in Packages

    cd into your Packages folder  
    git clone git:// .
  • By downloading the files and placing them in a directory under Packages, such as DetectSyntax or User

    If you don't put the files in Packages/User (you can, but probably shouldn't), make sure they live in Packages/DetectSyntax. If you download and extract a compressed archive from GitHub, the directory will be phillipkoebbe-DetectSyntax. Remove phillipkoebbe-.


DetectSyntax is based on the idea that there are rules for selecting a certain syntax. You define the rules, the plugin checks them. The first one to pass wins. If you have need of multiple conditions that must be met, you should use the function rule. See the default settings file for more on function rules.

Create your own rules in Packages/User/DetectSyntax.sublime-settings. The easiest way to get started is to just copy the default settings file found in Packages/DetectSyntax/DetectSyntax.sublime-settings to your user directory and modify it to meet your needs. Make sure you rename the default_syntaxes key to just syntaxes. If you don't, you will overwrite the default syntaxes and they will not work.

See the default settings file for examples and comments related to creating rules.


It all started by forking the plugin created by JeanMertz (1). I modified it quite extensively until I ended up with something entirely my own (2). @maxim and @omarramos commented on the gist and suggested it should be part of Package Control. As I had created it solely for my own consumption, it seemed a bit "hard-coded" to be valuable as a package, but then I took a look at SetSyntax (3) and saw how using settings would make it very flexible. That set me on the path that led to DetectSyntax.



  • Fork the project.
  • Use topic branch.
  • Make pull request.



  • Added support for zsh config files. [Thanks Benjamin Smith]


  • Added ability to match all rules. [Thanks for the idea Kirk Strauser]


  • Added jbuilder to the Ruby rule. [Thanks Aaron Crespo]
  • Expanded Vagrantfile rule to catch extensions (like Vagrantfile.local).



  • User-defined syntax rules get processed first now. [Closes #11]


  • Added rule to Ruby syntax for Puppet (pp) files.



  • Fixed improper handling of directories with non-ascii characters [Closes #5, thanks Andrew Dryga]


  • Better handling of file defining a function potentially not existing.


  • Added new_file_syntax so new files can have a syntax applied immediately.


  • Added rule for *.thor (thanks Magnus Rex).


  • Renamed the syntaxes key to default_syntaxes so it is no longer necessary to duplicate default rules in User/DetectSyntax.sublime-settings.


  • Added rule type of 'binary' which builds a shebang regexp for the user.


  • Check to make sure the syntax file exists before trying to set it. [Closes #3, thanks tito]