autocomplete - 仅在字符后使用制表键自动完成 Sublime 文本
解决方案
正如您所经历的那样,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多行选择时缩进的旧行为将保留,当我们的条件不满足时其他默认绑定也将保留。)
推荐阅读
- python - 如何在数据集上创建、训练和打印 RandomForestClassifer 的结果
- r - 如何从动物园对象中获取特定时间的所有日期?
- ruby-on-rails - 在 Rails 中制作可选控制器需要包含哪些模块?
- ios - 从 macOS 上的 Cocoa 应用程序访问 iOS 设备
- google-cloud-functions - 将 TensorflowJS 模型保存到 Firebase 存储的最佳实践?
- python - 将单例矩阵的熊猫数据帧转换为数字数据帧
- c# - DataGrid - 添加不属于数据的行(用于“目录导航”)
- genexus - 如何在 Genexus 中解决这个 GXTest?
- mysql - 我使用node.js创建了一个rest api,在.get方法中我想取回一个json数组
- reactjs - 检查是否使用反应钩子卸载了组件?