Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sublime: Convert 2 Spaces to 4
[
{
"args": null,
"command": "select_all"
},
{
"args":
{
"set_translate_tabs": true
},
"command": "unexpand_tabs"
},
{
"args": {
"setting": "tab_size",
"value": 4
},
"command": "set_setting"
},
{
"args":
{
"set_translate_tabs": true
},
"command": "expand_tabs"
}
]
@seniorpreacher

This comment has been minimized.

Copy link

commented Oct 26, 2013

I've created a macro to convert indentation from spaces to tabs, if anyone interested: https://gist.github.com/Edifice/7172119

@michaelhays

This comment has been minimized.

Copy link

commented Jul 28, 2015

Thanks!

@rayryeng

This comment has been minimized.

Copy link

commented Sep 4, 2015

Thanks a lot for this!

@TimHeckel

This comment has been minimized.

Copy link

commented Sep 14, 2015

For those of you (like me) initially confused on where to save the file, you can drop it here:

~/Library/Application Support/Sublime Text 3/Packages
@gsportelli

This comment has been minimized.

Copy link

commented Jun 20, 2016

To make it work I had to add tab_size setting to 2 before expanding:

[
    {
        "args": null,
        "command": "select_all"
    },
    {
        "args": {
            "setting": "tab_size",
            "value": 2
        },
        "command": "set_setting"
    },
    {
        "args":
        {
            "set_translate_tabs": true
        },
        "command": "unexpand_tabs"
    },
    {
        "args": {
            "setting": "tab_size",
            "value": 4
        },
        "command": "set_setting"
    },
    {
        "args":
        {
            "set_translate_tabs": true
        },
        "command": "expand_tabs"
    }
]
@nicooprat

This comment has been minimized.

Copy link

commented Sep 8, 2016

Worked better for me when translating spaces to tabs first:

[
    {
        "command": "select_all",
        "args": null
    },
    {
        "command": "expand_tabs",
        "args": {"set_translate_tabs": true}
    },
    {
        "command": "set_setting",
        "args": {"setting": "tab_size", "value": 4}
    },
    {
        "command": "unexpand_tabs",
        "args": {"set_translate_tabs": true}
    },
    {
        "command": "set_setting",
        "args": {"setting": "tab_size", "value": 2}
    },
    {
        "command": "expand_tabs",
        "args": {"set_translate_spaces": true}
    }
]
@ctf0

This comment has been minimized.

Copy link

commented Jan 2, 2017

2 > 4 space

[
    {
        "command": "unexpand_tabs",
        "args": {"set_translate_tabs": true}
    },
    {
        "command": "set_setting",
        "args": {"setting": "tab_size", "value": 2}
    },
    {
        "command": "expand_tabs",
        "args": {"set_translate_tabs": true}
    },
    {
        "command": "unexpand_tabs",
        "args": {"set_translate_tabs": true}
    },
    {
        "command": "set_setting",
        "args": {"setting": "tab_size", "value": 4}
    },
    {
        "command": "expand_tabs",
        "args": {"set_translate_tabs": true}
    }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.