Sublime Text 3 - Detect syntax based on file header

ApplySyntax plugin does handle cases, when you need different syntax for files with the same extension and many more.

To expand on Gerard Roche's answer, if you're wondering how to find these syntax definition files in Sublime Text 3, I found this answer helpful.

To summarize: on MacOS X, the package files live at /Applications/Sublime and are all zip files even if they don't show the extension. To change the syntax definitions,

  1. Create a new folder where you'll unzip to (if you unzip in place, it's harder to keep track of all the files).
  2. Copy the language file you wish to modify into this folder and unzip it. Then rename the previous language file as a backup.
  3. Open the <Language>.sublime-syntax file and change the first_line_match rule to whatever you need.
  4. Zip all of the files back together again using a no-compression zip, name the zip file the same as the original file and then move it back out to the Packages folder.

Thanks to xmnboy for pointing out that the zip files can't be compressed.