2017-01-04 23 views
4

當我點擊一個新行按鈕時,Sublime Text有3種方法來處理括號縮進。如何設置ST3中的括號縮進行爲

1.curly支架

xxx = { 
    |cursor| 
} 

2.parenthesis

xxx = (
    |cursor|) 

3.square支架

xxx = [ 
|cursor|] 

我怎麼能設置他們都表現得像花括號

回答

8

在德故障鍵綁定,有這樣:

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

,其提供用於按壓輸入{}括號之間的功能。該宏添加2個換行符,將光標移到第一個換行符後面並重新添加行。

可以因此通過增加給你的用戶的按鍵組合實現()[]之間相同的功能:

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

嗨。這有助於我,但我仍然得到不同的行爲。隨着parantheses關閉一個會縮進光標和方括號的光標不縮進.. – ViggoV

+0

我想這是由於縮進規則ST在您的情況下使用@ViggoV - 你的語言/語法遇到這種行爲? –

+0

Javascript/ES6。我發現這個:https://stackoverflow.com/questions/22865347/smart-indenting-of-brackets-parenthesis-in-sublime-text-2,但它沒有伎倆..我已經恢復到vscode暫時... – ViggoV