Settings for many Sublime Text 3 configuration files, for example, with the extensions .sublime-settings , .sublime-keymap or .sublime-theme are stored in JSON format. Not only I think that it is less convenient compared to Hjson or YAML, in particular, because if there are comments or a comma in the end of an array in the file, it becomes invalid .

For example, I made changes to my theme file with Sublime Text supported 3 comments and commas, which does not look very nice:

 [ //Полосы прокрутки {"class": "scroll_bar_control", "layer0.tint": [0, 250, 154] }, // Вертикальный бегунок, требуется добавить файлы, см. http://stackoverflow.com/a/31094548/5951529 {"class": "puck_control","layer0.texture": "User/Theme - SashaSublime/vertical_white_scrollbar.png", "layer0.tint": [200, 170, 250], "layer0.opacity": 1.0, "layer0.inner_margin": [0, 10], "content_margin": [8, 12], "blur": false, },] 

I need comments, I do not want to delete them. Is there a beautifier that puts in order the indentation of Sublime Text 3 configuration files?

    1 answer 1

    Will not help

    Formatters for valid JSON

    Online

    Like JSON Editor online or JSON Formatter & Validator . They will show that JSON is invalid and will not be formatted.

    Sublime Text Plugins

    Pretty JSON and Indent XML (beautifier for JSON and XML) also do not format non-valid files. JSON Reindent is not working correctly for me, errors are issued to the console.

    Other tools

    Jsonnet removes comments.

    Replacing comments with the "comment" parameter

    They write that you can replace the comment // Саша непостижима by something like {"comment": "Саша непостижима"} , whether it is inside the array (without {curly brackets}, "comment": "Саша непостижима" ) or in front of them. This can be done with regular expressions. Example:

    Search : \/\/ (.*)\n( {4}){
    Replace : { "comment": "$1",
    Demonstration : https://regex101.com/r/fD9hW0/1

    Or automatically, with comment-json .

    The configuration is saved, JSON becomes valid, and it can be formatted in the ways above. It seems that the problem is resolved, but in the console ( Ctrl + ' (typewritten reverse apostrophe, the symbol is located on the same key where Cyrillic "e")) will constantly issue no such prop comment .

    No such prop comment

    Replacing comment with any other word will not solve the console problem. I do not know how this affects the functionality of Sublime Text 3, however, it is clear that using the console, where errors pop up and down, is not very comfortable.

    Will help

    JSON is a component of ECMAScript , and you can format files with JSON syntax using the best in your opinion prettifier for JavaScript. For Sublime Text on Stack Overflow, we recommend using the HTML / CSS / JS Prettify plugin .

    After installing HTML / CSS / JS Prettify, it will not format the default configuration files of Sublime Text 3, its configuration is required, which is different from the configuration of other plug-ins. PreferencesPackage SettingsHTML/CSS/JS PrettifySet Prettify Preferences → copy the entire contents of the opened file (if you only copy individual lines to the new file, the values ​​in which are changed to the required ones, the plugin will not work correctly). PreferencesBrowse PackagesUser → in the folder that opens, create a file .jsbeautifyrc → paste the copied, change

     "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc"], 

    on

     "allowed_file_extensions": ["js", "json", "jshintrc", "jsbeautifyrc", "sublime-keymap", "sublime-theme", "sublime-settings"], 

    If necessary, we similarly insert other extensions → save the file. The .jsbeautifyrc file can be placed in other folders, but if you create it in User , HTML / CSS / JS Prettify will work with the files of the necessary extensions, wherever they are. .jsbeautifyrc necessary to create a custom .jsbeautifyrc file, because if you edit the default, then when updating the plugin, all custom settings will be reset.

    Ctrl + Shift + PHTMLPrettify → JSON from the question the plugin will format as follows:

     [ //Полосы прокрутки { "class": "scroll_bar_control", "layer0.tint": [0, 250, 154] }, // Вертикальный бегунок, требуется добавить файлы, см. https://stackoverflow.com/a/31094548/5951529 { "class": "puck_control", "layer0.texture": "User/Theme - SashaSublime/vertical_white_scrollbar.png", "layer0.tint": [200, 170, 250], "layer0.opacity": 1.0, "layer0.inner_margin": [0, 10], "content_margin": [8, 12], "blur": false, }, ] 

    Plugins for working with Sublime Text configuration files

    Preferences Editor

    Allows you to edit .sublime-settings files not manually, but through the Quick Panel of the plugin; The settings file will be formatted. Suppose we want binary files to open with the Hex Viewer plugin. Install the Preferences Editor via Package Control → Ctrl + Shift + PEdit Preferences: Edit Settings...hex_viewerauto_open

    Auto open

    true . At the bottom there is a panel where comments are given to the selected parameter, if the developers brought them.

    Comments

    Check: PreferencesPackage SettingsHex ViewerSettings - User → the file will be like this.

     { "auto_open": true } 

    The settings are written to the user file, so that when the plugin is updated, they will not fail.

    Trying to open a binary file → Hex Viewer plugin should be activated automatically.

    With their help, you can simplify the editing of .sublime-settings files, but only them. I did not find ready-made plug-ins for automatic editing of other configuration files.

    Preference Helper

    The plugin allows you to quickly navigate to the .sublime-settings files, which, however, will have to edit manually. Install the pluginPreference Helper: Open *.sublime-settings → enter the name of the plugin / syntax / built-in tool whose settings we want to change → the settings file opens.

    Preference Helper

    I use the Preferences Editor to be more comfortable.