I
I
italant2020-02-06 01:35:08
Sublime Text
italant, 2020-02-06 01:35:08

How to make proper bracket alignment in Sublime text 3 after "Enter" is pressed?

When you open "{" the bracket is automatically closed, and if you press enter, there will be a nice alignment.

5e3b4218b674f285794123.png

If you do the same for "(", then you get garbage

5e3b425357ecb254865567.png

. For "[" no indented newline is created.

5e3b42e148afc687716302.png

How can I make sure that after closing ")" or "]" exactly the same alignment works as for "}"?
To get this kind of result.

5e3b42fe4070c715634181.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
italant, 2020-02-06
@italant

In fact, everything is simple.
In the Key Bindings settings there is such an option

{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
    [
      { "key": "setting.auto_indent", "operator": "equal", "operand": true },
      { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "\\{$", "match_all": true },
      { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
  }

The macro "Add Line in Braces.sublime-macro" is launched, which is responsible for such expansion of { } brackets.
Add support ( and [ to the regular expression and everything is ok)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question