Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save joshmfrankel/5707020 to your computer and use it in GitHub Desktop.
Save joshmfrankel/5707020 to your computer and use it in GitHub Desktop.
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
Copy link

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

@michaelhays
Copy link

Thanks!

@rayryeng
Copy link

rayryeng commented Sep 4, 2015

Thanks a lot for this!

@TimHeckel
Copy link

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
Copy link

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
Copy link

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
Copy link

ctf0 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