![Sublime 3:如何让 TAB 重新缩进当前行或选定的区域(如果存在)?](https://linux22.com/image/1499472/Sublime%203%EF%BC%9A%E5%A6%82%E4%BD%95%E8%AE%A9%20TAB%20%E9%87%8D%E6%96%B0%E7%BC%A9%E8%BF%9B%E5%BD%93%E5%89%8D%E8%A1%8C%E6%88%96%E9%80%89%E5%AE%9A%E7%9A%84%E5%8C%BA%E5%9F%9F%EF%BC%88%E5%A6%82%E6%9E%9C%E5%AD%98%E5%9C%A8%EF%BC%89%EF%BC%9F.png)
TAB 键默认只是放置一个制表符,并且仅根据几个上下文进行缩进,对此我不太理解。
{ "keys": ["tab"], "command": "reindent", "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
]
},
我想reindent
默认设置 tab,但删除上下文
{ "keys": ["tab"], "command": "reindent", "args": {"single_line": false} },
让 sublime 一次性重新缩进整个文件。我不想这样做,因为我想保留 shell heredocs 的自定义缩进。
答案1
要使在光标内的所有行都有选择时按 Tab 键重新缩进当前行,您只需执行以下操作:
{ "keys": ["tab"], "command": "indent", "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": false }
]
},
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "\t", "exact": true}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": false }
]
},
上下文结构
钥匙:需要查询其值的上下文的名称。
操作员:针对键值执行的测试类型。默认为相等。
操作数:根据该值测试通过 key 返回的结果。
全部匹配:要求所有选择都通过测试。默认为 false。
http://docs.sublimetext.info/en/latest/reference/key_bindings.html#structure-of-a-context http://docs.sublimetext.info/en/latest/reference/key_bindings.html#context-operands