Question

Is there a way to improve Sublime text 2's curly bracket wrapping? For example, I have the following PHP code:

$isThisPointless = true;
$uselessString = 'Meh.';
$uselessInt = 83;

Let's say I want to wrap it inside an if statement. So I go ahead, select the code and press '{' and Sublime Text magically wraps it in curly brackets. Great! Only, indentation is a mess. now my code is more like:

{$isThisPointless = true;
        $uselessString = 'Meh.';
        $uselessInt = 83;}

While I was expecting to achieve this instead:

{
    $isThisPointless = true;
    $uselessString = 'Meh.';
    $uselessInt = 83;
}

Google search suggested the bracketeer plugin. I tried using it and while it removes the ugly indentation, it still doesn't indent the block the way I want.

Is there a way to make Sublime Text do this?

Was it helpful?

Solution

I've figured this out using a custom snippet:

<snippet>
    <content><![CDATA[
{
    $SELECTION$1
}
]]></content>
    <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
    <!-- <tabTrigger>hello</tabTrigger> -->
    <!-- Optional: Set a scope to limit where the snippet will trigger -->
    <scope>source.js, source.php</scope>
</snippet>

... and then binding that snippet to a key combination. If you use the snippet you might want to change the scope (depending on the language you need), or just disable it entirely.

I'll leave the answer here just in case somebody needs it!

OTHER TIPS

The snippet mentioned above didn't work for me, so I've created a plugin specifically for this purpose:

https://github.com/Epskampie/sublime_indent_and_braces

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top