Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
429 views
in Technique[技术] by (71.8m points)

sublimetext3 - How to set bracket indentation behavior in ST3

Sublime Text has 3 ways to handle brackets indentation when I hit a new line button.

1.curly bracket

xxx = {
  |cursor|
}

2.parenthesis

xxx = (
  |cursor|)

3.square bracket

xxx = [
|cursor|]

How could I set all of them to behave like curly bracket

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the Default keybindings, there is this:

{ "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 }
    ]
},

which provides the functionality for pressing Enter between the { and } braces. The macro adds 2 newlines, moves the cursor to after the first one and reindents the line.

You can therefore achieve the same functionality between ( and ) and [ and ] by adding this to your user keybindings:

{ "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 }
    ]
},
{ "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 }
    ]
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...