9

I write JS projects in ES5 and ES6. I installed Babel-Sublime for highlighting Babel supported code. Now, I open a .js file written in ES6, goto "View -> syntax -> Open all with current extension as : Javascript (Babel)", but this causes my ES5 code to also switch to Javascript (Babel). Basically,the JavaScript (Babel).sublime-settings file is updated in the User folder with the extension mapping and the change is applied globally to all my projects. So, is there a way to specify "syntax to extension" mapping per folder or per project basis

1 Answer 1

13

First you can specify project-level settings using your_project_name.sublime-project file. Take a look at Project menu and the sublime documentation.

Though, sublime doesn't support syntax settings in the .sublime-project files. So you have to use Sublime Project Specific Syntax package. This works for me with Sublime Text 3. Pay attention to use the Project Specific Syntax > Copy syntax setting to clipboard menu item.

For Babel-Sublime syntax highlighting following should work:

{
    "folders":
    [
        {
            "path": "."
        }
    ],
  "syntax_override": {
    "\\.js$": ["Babel", "JavaScript (Babel)"]
  }
}
3
  • Awesome. That package worked perfectly. I still wish there would be a folder level syntax_override option, to avoid creating sublime-projects, which when committed to shared repos may not be useful to everyone
    – tapsboy
    Nov 15, 2015 at 21:46
  • @tapsboy years too late, but in case anyone else comes across this, you can store the project file (.sublime-project) outside the project folder/s, ie. outside the repo, if that's useful. I do that for the reason you identified.
    – Erland
    Jan 7 at 23:05
  • Thanks. I don't know how ChatGPT can ever replace this amazing community
    – tapsboy
    Jan 9 at 1:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .