如何阻止Sublime Text 3在花括号中包裹线条

时间:2013-07-28 04:17:01

标签: curly-braces sublimetext3

我正在使用看起来像这样的Handlebars(.hbs)文件:

<div>
  ...

  _
  <button {{action "signin"}}>Sign in</button>
</div>

当我将光标放在下划线位置并输入一个大括号{。它将整个<button>行包装在大括号中:

{
<button {{action "signin"}}>Sign in</button>
}

但我想要的只是:

{}
<button ...

[和(没有这种行为。有没有办法禁用Sublime Text的这个功能?我看了一下键绑定但是找不到方括号和花括号之间的区别,这使得它们的行为不同

2 个答案:

答案 0 :(得分:1)

我的解决方案依赖于您应用了语法,因此可能会或可能不会开箱即用。

尝试将以下内容添加到用户密钥绑定中。

{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{${0:$SELECTION}}"}, "context":
    [
        { "key": "indented_block", "match_all": true },
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "source.handlebar", "match_all": true },
    ]
}

我猜到了车把的范围,所以如果你需要改变它。如果您没有与文件类型相关联的语法定义,请注释,我将更新我的答案。

为了将来参考,我发现在控制台中执行“sublime.log_commands(True)”运行命令。从那里我找到了相关的键绑定,并创建了一种覆盖特定类型文件的方法。

答案 1 :(得分:0)

我在JSX文件的Sublime Text 3中遇到了同样的问题。在阅读了skuroda的答案后的评论后,我能够通过复制/覆盖密钥和&amp;来解决它。 &#34; wrap_block&#34;的上下文绑定但在命令和subgs中插入&#34; insert_snippet&#34;结合。

看起来像这样(添加到用户密钥绑定列表):

    { "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "context":
        [
            { "key": "indented_block", "match_all": true },
            { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
        ]
    },