How to Change Syntax for a Specific Folder in Sublime Text 3

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest