我有一个初始的开始场景,其中|表示我的光标:
for(int i=0;i<n;i++){|}按回车键后的结果:
for(int i=0;i<n;i++){
|}期望的结果:
for(int i=0;i<n;i++){
|
}我尝试了this,但它没有解决我的问题。
我使用了下面的键绑定,但它不起作用:
[
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "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 }
]
}
]另外,我的这些键绑定设置如下:
"auto_indent": true,
"smart_indent": true,
"indent_to_bracket": true,
"trim_automatic_white_space": true,我怎么才能修复它?
编辑:-我卸载了Sublime Text4并安装了Sublime Text3。它工作得很好。我会坚持下去的。
发布于 2021-06-10 22:09:09
完整的键绑定应该是:
[
{ "keys": ["enter"], "command": "insert_snippet", "args": {"contents": "\n\t$0\n"}, "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 }
]
}
]如果您希望方括号[ ]出现相同的行为,则需要以相同的方式对它们进行转义,因为它们在正则表达式中也是特殊字符。
编辑
下面是直接从Sublime Text 3复制的快捷键,在ST4中也是一样的:
[
{ "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 }
]
},
]https://stackoverflow.com/questions/67892845
复制相似问题