Giles Butler

Backpacking around the web.

Sublime Text 2 Indentation Tip

Just thought I’d share this quick shortcut I’ve found in Sublime. I know how picky devs can be about whether to use spaces or tabs for indentation, everyone likes there own setup right?

Well I can’t stand spaces and luckily ST2 has an awesome feature to switch to tabs without messing up your layout – just head into View -> Indentation -> Convert Indentation to Tabs or the opposite to Spaces  if your that way inclined. Now that’s a really handy feature but its buried a few levels down in the menu so to make things quicker you can use the command pallete CMD + Shift + P  and start typing Indent  and it should come up, the more you use it the better ST2 starts to know what you are looking for so after a few times it should be there instantly.

But there’s also another way which could be even quicker depending on your workflow. You can assign a key binding to the command via Preferences -> Key Bindings – User. After a quick search of the ST2 docs where I found the name for the command ‘unexpand_tabs‘, I have assigned it to the letters ‘tt‘, I was thinking ‘to tabs‘, anyway it works well for me.

So now all I have to do is switch to Command Mode by hitting Escape and then hit tt so my whole document is converted to tabs then I hit i and I’m back into Insert mode again, pretty nifty. This method assumes that you are running in vintage mode. Below is the code for your key bindings.

    { "keys": ["t", "t"], "command": "unexpand_tabs",
        "context": [{ "key": "setting.command_mode", "operand": true }]}

I hope this helps you out and makes your coding all that bit quicker, if you have any questions or find any more tips then feel free to leave them in the comments below.


    Your email address will not be published. Required fields are marked *