Sublime Forum

Alternate indentation

#1

I would like to switch to SublimeText, but I can’t find out if/how alternate code indentation styles are possible.

I prefer different bracketing/indentation style, mostly I use the Ratliff style: en.wikipedia.org/wiki/Indent_style#Ratliff_style – I use it in Javascript, CSS, Less etc. I need auto-indetation, I want to use snippets, but all these features force me to use your indentation style. Though I want the closing bracket to be indented like this:

function some(arr) { var i, str = ''; for (i=1;i<=arr.length;i++) { str += arr* + i; } return str; }
or

body { background: white; }
Is it possible to work like this with SublimeText? I really don’t want to indent each closing bracket manually… :frowning:*

0 Likes

#2

Snippets are not part of Sublime Text, they are from packages (add ons). It’s true that ST comes with some default packages, and that confuses a lot of people.

If you don’t like how those snippets work, make your own or modify the ones you use. It’s really easy and you will start scratching the surface of what ST is capable of.

For example:

<snippet>
    <content><![CDATA[
${1:tagName} {
    $2
    }
]]></content>
    <scope>source.css</scope>
    <tabTrigger>css declaration</tabTrigger>
</snippet>

docs.sublimetext.info/en/latest/ … ppets.html

0 Likes

#3

Well, maybe it can be fixed in snippets. But it doesn’t solve normal code typing.

#1: If you type a closing bracket on an indented position on a new line, ST2 automatically moves it one position back to the left:

xxx {
   aaa
   bbb
   }

is immediatelly changed to:

xxx {
   aaa
   bbb
}

#2: If you put the cursor inside empty curly brackets and press enter, it’s formatted like this:

{ | }
I can’t avoid it. What I need is this:

{ | }
or at least this (Coda or BBEdit do this, I just hit the Enter twice to have what I need):

{ |}

0 Likes

#4

Everything you are saying is true, and I really can’t help you if you don’t want to use snippets.

What I don’t understand, is why you’d prefer to write “manually” those repetitive code structures that involve using braces (css declarations, function, if else, etc), instead of using snippets. It would save you a lot of time, and you could have the code exactly the way you want it… isn’t that the point of using ST?

0 Likes

#5

Yes, I totally agree with you. Most of the new code can be written using snippets, and they will solve my problem in 99 % here. There’s a bit different situation on editting an existing code, where snippets can’t be used so often.

OK anyway. I’ll try and create a basic set of snippets and I’ll try ST2 in my workflow for a couple of days if it could work. (Though I still think making indetation parametric and supporting other alternate indentation styles in the editor would be nice.)

0 Likes