如何解决按 Enter 后没有得到额外的行 Sublime Text 3 编辑
我有这个初始场景,其中 |
表示我的光标:
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","operand": true,"match_all": true },{ "key": "preceding_text","operator": "regex_contains","operand": "{$",{ "key": "following_text","operand": "^}","match_all": true }
]
}
]
我的这些键绑定也设置如下:
"auto_indent": true,"smart_indent": true,"indent_to_bracket": true,"trim_automatic_white_space": true,
我该如何解决?
编辑:- 我卸载了 Sublime Text4 并安装了 Sublime Text3。它工作正常。我会坚持的。
解决方法
大括号是正则表达式中的特殊字符,因此您需要更改 "regex_contains"
"operand"
以反映这一点。完整的键绑定应该是:
[
{ "keys": ["enter"],"command": "insert_snippet","args": {"contents": "\n\t$0\n"},"context":
[
{ "key": "setting.auto_indent","operator": "equal","operand": true },{ "key": "selection_empty","operand": true,"match_all": true },{ "key": "preceding_text","operator": "regex_contains","operand": "\\{$",{ "key": "following_text","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","match_all": true }
]
},]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。