Sublime Forum

Convert spaces to tabs upon opening a file, and tabs to spaces on save

#1

Most code examples on the web use spaces and so does my team. I prefer tabs, but I’d like to keep things consistent.

Is there a configuration or plugin that will automatically convert a file using spaces to tabs upon opening it, and also convert it back to spaces upon saving?

Ideally it would behave like this:
Spaces (width: 2) <—> Tabs (width: 4)

I setup two keybinds using the Chain of Command plugin (allows multiple commands per keybind), but I’d still like to be able to automate this like described in the title:

{ 
    "keys": ["ctrl+shift+alt+t"], 
    "command": "chain",
    "args": {
        "commands": [
            [ "set_setting", { "setting": "tab_size", "value": 2 }],
            [ "expand_tabs", { "set_translate_tabs": true }]
        ]
    }
},
{ 
    "keys": ["ctrl+alt+t"], 
    "command": "chain",
    "args": {
        "commands": [
            [ "unexpand_tabs" ],
            [ "set_setting", { "setting": "tab_size", "value": 4 }]
        ]
    }
},
0 Likes