【发布时间】:2018-10-18 15:42:16
【问题描述】:
【问题讨论】:
【问题讨论】:
如您所见,ST 的默认行为是“插入最佳补全”,此时插入符号前面只有一行空格。
幸运的是,ST 非常可定制,我们可以根据您的需要覆盖此行为。
为此,请将其添加到您的用户键绑定中:
{ "keys": ["tab"], "command": "indent",
"context":
[
{ "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "not_regex_match", "operand": "^$", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
]
},
{ "keys": ["tab"], "command": "insert", "args": { "characters": "\t" },
"context":
[
{ "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
]
},
这告诉 ST,当你按下 Tab 时,它应该在满足以下条件时缩进文本: - 没有选择 - 插入符号位于行首或仅以空格开头(即缩进) - 在插入符号之后(/ 右侧)有一些文本 - 自动完成弹出窗口不可见
此外,当所有这些条件都为真时,除了插入符号后的行上有文本,我们告诉 ST 插入一个制表符。注意:如果您使用空格进行缩进,ST 会将其转换为正确的空格数。
(当您在多行选择中按 Tab 时的旧缩进行为将保留,当我们的条件不满足时其他默认绑定也将保留。)
【讨论】: