【问题标题】:I want tab to insert a tab in Sublime Text but it activates the autocomplete我希望选项卡在 Sublime Text 中插入一个选项卡,但它会激活自动完成功能
【发布时间】:2015-03-28 12:48:08
【问题描述】:

我正在使用Sublime CodeIntel,我喜欢autocomplete,但是当我尝试插入标签时它会弹出并插入单词。我希望制表符始终插入制表符,除非光标之前的字符是字母。

我认为这可以通过用户 keymap 来完成,让 tab 键查看上下文,但我不知道该怎么做。

【问题讨论】:

    标签: ide sublimetext sublimetext3 keymaps


    【解决方案1】:

    类似下面的东西应该可以工作。您可能需要使用键绑定的顺序。将以下内容添加到您的用户键绑定中

     {
        "keys": ["tab"], "command": "insert", "args": {"characters": "\t" }, "context": [
            { "key": "preceding_text", "operator": "regex_contains", "operand": "[^a-zA-Z]$", "match_all": true }
        ]
     }
    

    请注意,我没有安装 SublimeCodeIntel,所以不确定它会如何运行。

    作为一个不错的调试提示,在 ST 控制台中输入 sublime.log_commands(True) 以查看针对特定键绑定执行的命令。可能有助于确认命令是否按预期运行。

    【讨论】:

    • 谢谢!这行得通,我只是稍微修改了正则表达式。 { "key": "preceding_text", "operator": "regex_contains", "operand": "\\s$", "match_all": true }
    【解决方案2】:

    如果您在 Windows 上,一个快速的解决方法是使用 Autohotkey。 您可以将任何键分配给 4 个空格,如下所示

    `::
    Send {Space 4} ; when pressed ` enters four times Space bar
    Return
    

    【讨论】:

    • 谢谢,但这不是我想要的。我的 tab 键工作正常,除非当我真正想键入一个选项卡时出现自动完成。我需要 tab 键是“聪明的”,并且知道什么时候显示自动完成功能合适,什么时候不合适。这可以根据上下文来确定。要么我正忙着输入一个单词(应该显示自动完成),要么我没有(应该输入一个标签)。
    【解决方案3】:

    试试这个... 覆盖 tab 键以用作 缩进键insert tab char

    首选项 > 键绑定

    [
        { "keys": ["tab"], "command": "insert", "args": {"characters": "\t"} },
        { "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 }
            ]
        },
        { "keys": ["tab"], "command": "indent", "context":
            [
                { "key": "text", "operator": "regex_contains", "operand": "\n" }
            ]
        },
        { "keys": ["tab"], "command": "next_field", "context":
            [
                { "key": "has_next_field", "operator": "equal", "operand": true }
            ]
        }
    ]
    

    【讨论】:

      猜你喜欢
      • 2013-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-23
      • 2015-10-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多