首页 > 解决方案 > 仅在字符后使用制表键自动完成 Sublime 文本

问题描述

Sublime text 3 是否可以配置为仅在光标位于字符之后而不是之前时按 tab 键时自动完成?

-done 不应添加

我想避免 -done完成,我想添加一个制表符空间。

标签: autocompletesublimetext3

解决方案


正如您所经历的那样,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多行选择时缩进的旧行为将保留,当我们的条件不满足时其他默认绑定也将保留。)


推荐阅读