Autocomplete 如何防止升华文本2吞没收尾括号、引号和括号?

Autocomplete 如何防止升华文本2吞没收尾括号、引号和括号?,autocomplete,sublimetext2,editing,brackets,Autocomplete,Sublimetext2,Editing,Brackets,升华有这样的行为,当你不得不用很多括号输入结构时,这真的很烦人。当你键入(< /代码>时,添加())/>代码,并将光标放在中间,所有的罚款,如果你将键入 ,它将悄悄地吞下关闭支架。 当输入长regexp时,这真的很烦人,因为括号很快变得不平衡,这让我发疯。所以你最终得到了类似于([a-z])的结构 所以问题是-有没有办法禁用它?如果我键入一个结束括号,我希望它保持不变,而不是被吞下 我在谷歌上查过Supreme配置,但似乎没有人介意这种行为。我用错了吗 更新 您可能还想查看快捷方式 完整版本,允

升华有这样的行为,当你不得不用很多括号输入结构时,这真的很烦人。当你键入<代码>(< /代码>时,添加<代码>())/>代码,并将光标放在中间,所有的罚款,如果你将键入<代码> <代码>,它将悄悄地吞下关闭支架。

当输入长regexp时,这真的很烦人,因为括号很快变得不平衡,这让我发疯。所以你最终得到了类似于
([a-z])
的结构

所以问题是-有没有办法禁用它?如果我键入一个结束括号,我希望它保持不变,而不是被吞下

我在谷歌上查过Supreme配置,但似乎没有人介意这种行为。我用错了吗

更新

您可能还想查看快捷方式

完整版本,允许您使用
()
进行键入,但如果您输入了任何文本,则不会吞下结束符号:

  { "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^\"]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "match_all": true }
      ]
  },
  { "keys": [")"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
      ]
  },
  { "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "'$", "match_all": true }
      ]
  },
  { "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "[$", "match_all": true }
      ]
  },
  { "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "context":
      [
          { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
          { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
          { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true },
          { "key": "preceding_text", "operator": "regex_contains", "operand": "{$", "match_all": true }

      ]
  }
重新定义
键绑定:

{ "keys": [")"], "command": "insert", "args": {"characters": ")"} }
编辑:另一种方法是启用/禁用启用的自动匹配设置(从而更改自动配对行为),您可以使用键盘快捷键随意切换:

{ "keys": ["alt+m"], "command": "toggle_setting", "args": {"setting": "auto_match_enabled"} }

我在浏览keybindings文件“preferences/key bindings-default”时发现,如果您选择一些文本并键入其中任何一个({[。它将在文本周围放置括号。

将其添加到您的用户keybindings文件中

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
    ]
}
它将覆盖一个键绑定,而不是插入一个结束括号,只是将光标向前移动一个位置。因此,本质上它应该完全按照您的要求执行

如果要完全禁用此行为,对于所有类型的方括号和引号,以下是完整的用户键绑定部分:

{ "keys": ["\""], "command": "insert", "args": {"characters": "\""}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\"", "match_all": true }
    ]
},
{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true }
    ]
},
{ "keys": ["'"], "command": "insert", "args": {"characters": "'"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^'", "match_all": true }
    ]
},
{ "keys": ["]"],"command": "insert", "args": {"characters": "]"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\]", "match_all": true }
    ]
},
{ "keys": ["}"], "command": "insert", "args": {"characters": "}"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\}", "match_all": true }
    ]
}
编辑:

如果要跳过结束方括号(如果光标正好位于开始方括号之后)并在所有其他情况下打印它,则可以拆分键绑定以区分这两种可能性:

{ "keys": [")"], "command": "insert", "args": {"characters": ")"}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "[^(]$", "match_all": true }
    ]
},
{ "keys": [")"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\($", "match_all": true }
    ]
},

如果前面的文本没有以大括号结尾,第一个将插入字符。如果前面的文本以大括号结尾,第二个将光标向前移动一个位置。如果您对正则表达式有点熟悉,您可以对所有其他类型的括号和引号做同样的操作。

虽然我不熟悉,但这是因此,post提供了一些信息。关于BracketHighLighter插件,它可能会提供一些缓解:stackoverflow.com/questions/10372004/how-to-change-style-of-matched-brands-in-sublime-text-2。谢谢,但这是为了突出显示括号。我试图找到的是当光标位于右括号上时防止松开括号的方法,而你需要这样做解决这个问题的另一种方法是暂时关闭括号匹配——例如:在使用正则表达式时。这个答案就是:它太简单了!:但是我必须重新定义所有键)}]" '. 还有其他方法吗?另一种方法是完全禁用自动配对,将启用的
自动匹配
更改为
false
对不起,禁用自动匹配将在我键入开始括号时禁用添加结束括号。我对此没有问题,但我希望能够键入一个结束符并查看它,因为自动匹配有时不起作用。简而言之,我想让Sublime表现得像Textmate。抱歉,这是错误的,关闭automatching会禁用所有功能。没错。我想停止配对引号,但我想继续配对大括号。禁用自动设置并不是完美的解决方案。当然,但在括号内键入一些文本并按
后,如果已经有括号,则不会在最后添加额外的括号。好的,我可以对方括号和花括号重复此操作。但是对于双引号和单引号我该怎么办呢?我刚刚编辑了我的答案。顺便说一下,我只是查看了默认的keybindings文件,并复制了每个部分,其中击键(例如“)”会产生一个“move”命令。您可以通过搜索“自动配对”找到这些部分。然后我将“移动”命令改为“插入”命令,插入适当的字符。这是可行的,但是有一个警告,如果它正好在开始的括号之后,你认为有可能让它吞下结束的括号吗?所以当我输入
function()
时,它不会以
function())
结束?有点像,如果你在一些文本前放一个开始的括号,它不会添加一个结束括号。哇,这太神奇了!谢谢,非常感谢。在找到你的答案之前我不知道我需要它。这让我很开心。