Sublime Forum

Auto-ident when putting curly braces around block

#1

How do I modify the auto-ident settings when wrapping a block in curly quotes?

Right now the default behavior almost always yields undesired results. Instead of just adding a tab to the block, it adds the current indentation to the next line.

Here’s an example. Let’s say I have these two lines of code.

doSomething();
doSomethingElse();

I want to wrap the second line in an if block, so on the line above it type if, then select the next three lines, and press “{”, here is the result:

doSomething();
if {
doSomethingElse();
}

Hmm, not what I wanted, guess I have to indent the code myself. But say we were indented 6 spaces (tabs are 2 spaces in the example) because we were already nested three levels deep, like so:

      doSomething();
      doSomethingElse();

And by the same procedure, I add an “if” keyword 6 spaces in at the top (where it belongs relative to the code above it), then select the next three lines, and press “{”

      doSomething();
      if {
            doSomethingElse();
      }

Now the code in it is indented 12 spaces instead of 8! I have to selected it and press shift+tab twice to get it where I want.

For a tool that’s usually amazingly intuitive this seems like very unusual behavior. Is there any way I can change this myself? I tried overwriting the bracket key bindings in my User/Default keymap but they don’t seem to override anything (even though I thought it took precendence?)

0 Likes