如何防止Sublime Text 2吞噬右括号,引号和括号?
崇高有这种行为,当你不得不input带有大量括号的结构时,这种行为有时真的很烦人。 当你键入(
它增加()
并把光标放在中间,一切正常,但是如果你会键入)
它会默默吞下右括号。
当inputlong regexps时,这真的很烦人,因为括号很不平衡很快,这让我疯狂。 所以你最终的结构像(([az])
。
所以问题是 – 有没有办法禁用这个? 如果我input一个闭括号,我希望它留下来,不要被吞噬。
我已经通过Sublimeconfiguration检查了一下,但没有人似乎介意这种行为。 我用错了吗?
更新
你可能想看看Sublime:跳出匹配的括号快捷键。
完整版本,允许您使用()
但如果您input了任何文本,则不会吞下结束符号:
{ "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": ")"}, "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 } ] }
它会覆盖一个键绑定,而不是插入一个右括号,只是将光标向前移动一个位置。 所以基本上它应该做你想要的。
如果要完全禁用这种行为,对于各种括号和引号,这里是完整的用户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 }, { "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 } ] },
如果前面的文本没有以左括号结尾,则第一个插入charcater。 第二个将光标向前移动一个位置,如果它以一个左括号结束。 如果你对正则expression式有一点熟悉,你可以对所有其他types的括号和引号做同样的处理。
重新定义)
键绑定:
{ "keys": [")"], "command": "insert", "args": {"characters": ")"} }
编辑 :另一种方法是启用/禁用auto_match_enabled
设置(从而改变自动配对行为),你可以使用键盘快捷键来随意切换:
{ "keys": ["alt+m"], "command": "toggle_setting", "args": {"setting": "auto_match_enabled"} }
当浏览键盘绑定文件的“首选项/键绑定 – 默认”时,我发现如果select了一些文本并键入其中的任何一个({[。将把括号放在文本的四周。