【问题标题】:Assign "Tab" (key) to "Tab" (indentation) in Sublime Text 3在 Sublime Text 3 中将“Tab”(键)分配给“Tab”(缩进)
【发布时间】:2017-06-03 10:55:32
【问题描述】:

在为 Rails 项目处理 Ruby 文件时,我一直在与自动完成作斗争
例如在写作时

email:      params[:email],
password:

我按 Tab 添加缩进(我知道 Sublime Alignment,但有时我更喜欢自己做),它变成password:key => "value",
我可以按很多空格,但我不喜欢它,而且我已经有一个标签键,我想使用它

我从旧答案中尝试过的东西没有成功:

首选项文件:

    "auto_complete": false,
    "tab_completion": false,
    "auto_complete_commit_on_tab": false,
    "auto_complete_selector": "source - comment",
    "auto_complete_size_limit": 4194304,
    "auto_complete_selector": "meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc",

键绑定:

          // show autocomplete on tab, not automatically, commit on enter.
    "keys"   : ["tab"], 
    "command": "auto_complete", 
    "args"   : {"default": "\t", "exact": false},
    "context":
    [
        { "key": "setting.tab_completion", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": ".*[^0-9][^\r ^\n ^\t ^\f]", "match_all": false },
    ], 


 "keys"      : ["tab"], 
 "command"   : "auto_complete", 
 "args"      : {"default": "\t", "exact": false},
 "context"   :
    [
        { "key": "setting.tab_completion", "operator": "equal", "operand": true },
        { "key": "preceding_text", "operator": "regex_match", "operand": "[][a-z]", "match_all": false },
    ], 

            //      method #2

  "keys"      : ["tab"], 
  "command"   : "insert", 
  "args"      : {"characters": "\t"}, 
  "context"   : 
        [
            { "key": "auto_complete_visible" }
        ]

        "auto_complete_triggers":
        [
            {
                "characters": "<",
                "selector": "text.html"
            }
        ],
        "auto_complete_with_fields": false,

【问题讨论】:

  • 你知道专用缩进键和非缩进键吗?在 Linux 和 Windows 上,键 ctrl+]ctrl+[ 将分别执行缩进和取消缩进。在 OSX 上使用 super+]super+[

标签: ruby-on-rails ruby autocomplete sublimetext3 indentation


【解决方案1】:

您可以设置以下键绑定以确保 Tab 在未打开自动完成弹出窗口时始终插入制表符(并且没有选择,因此您仍然可以阻止缩进文本):

{ "keys": ["tab"], "command": "insert", "args": { "characters": "\t" },
    "context":
    [
        { "key": "auto_complete_visible", "operator": "equal", "operand": false },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
    ],
 },

如果您只希望 Ruby on Rails 使用此功能,您可以添加以下上下文:

{ "key": "selector", "operator": "equal", "operand": "source.ruby.rails" }

【讨论】:

  • 我已经做到了(有和没有使用 Ruby 的第二部分),但它并没有改变我在帖子中描述的烦人行为
【解决方案2】:

在键映射中,这是由规则管理的:

{ "keys": ["tab"], "command": "next_field", "context":
        [{ "key": "has_next_field", "operator": "equal", "operand": true }]
    },

覆盖这条规则

{ "keys": ["tab"], "command": "next_field", "context":[]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-13
    • 2014-04-18
    • 2011-06-16
    • 2023-03-18
    • 2016-12-12
    • 2018-08-28
    • 2014-05-19
    • 2016-06-19
    相关资源
    最近更新 更多