Skip to content

Instantly share code, notes, and snippets.

Last active Apr 15, 2021
What would you like to do?
VSCode's Format on save for SublimeText

requirement: TypeScript package should be installed

Step 1: Create a new plugin (Tools > Developer > new plugin) with the following, save it as for example:

import sublime
import sublime_plugin

class FormatTypescriptOnSave(sublime_plugin.EventListener):
  def on_pre_save(self, view): 
    if "TypeScript" in view.settings().get("syntax") or "JavaScript" in view.settings().get("syntax"):


Step 2: Customize additional formatting settings in ~/.config/sublime-text-3/Packages/TypeScript/typescript/libs/, here I added "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": False

    def set_features(self):
        host_info = "Sublime Text version " + str(sublime.version())
        # Preferences Settings
        format_options = {
            "tabSize": self.tab_size,
            "indentSize": self.indent_size,
            "convertTabsToSpaces": self.translate_tab_to_spaces,
            "insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": False,
            "insertSpaceAfterFunctionKeywordForAnonymousFunctions": True, # False by default on SublimeText TypeScript
        self.service.configure(host_info, None, format_options)


create a .vscode/settings.json file (or edit your main settings ctrl+, or ctrl+shift+p Open settings (JSON)) with:

    "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
    "editor.formatOnSave": true, // of course
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment