2014-09-25 61 views
0

Sublime Text 3引用了自动配对功能,该功能完美无缺。但是,由于某种原因,当下面的字符是分号时,它停止工作。所以,在这里进入单或双引号:Sublime Text 3在分号前不加引号引号

echo^

会进入它们之间既报价和地方光标,而在这里做的一样:

echo ^; 

会造成崇高的文本3只开放单进入或双引号。

我在PHP中编程时遇到了一个小故障,我经常首先输入分号,然后回到那一行并编写实际的代码。许多片段和宏也输入分号。所以,在这种情况下,ST3的这种行为有点烦人。

是否有任何解释,为什么自动配对被限制在Sublime Text 3中,在分号之前无法工作?而且 - 最重要的是 - 有什么方法可以解决这个问题行为?

回答

1

默认情况下,卓异意志自动对引号仅当下列字符是\t(制表符)之一,(空间),)]}>,或在该行的末尾。幸运的是,通过创建基于默认密钥绑定的自定义密钥绑定,可以轻松修改此规则。开放Preferences -> Key Bindings-User并添加以下(如果该文件是空的,环绕一切与在开始时的开口方括号[并在结束[ <content> ]]):

// allow matched quotes before semi-colon 
// double quotes 
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "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": "^(?:\t| |\\)|]|\\}|>|$|;)", "match_all": true }, 
     { "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true }, 
     { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double", "match_all": true } 
    ] 
}, 

// single quotes 
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'$0'"}, "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": "^(?:\t| |\\)|]|\\}|>|$|;)", "match_all": true }, 
     { "key": "preceding_text", "operator": "not_regex_contains", "operand": "['a-zA-Z0-9_]$", "match_all": true }, 
     { "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.single", "match_all": true } 
    ] 
}, 

// curly brackets 
// parentheses and square brackets already work 
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "{$0}"}, "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": "^(?:\t| |\\)|]|\\}|$|;)", "match_all": true } 
    ] 
} 

每个规则中的关键线是这样的:

{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$|;)", "match_all": true }, 

如果你发现你想自动对之前另一个角色,只是把一管|分号之后"operand"并添加你想要的角色。

我应该注意到,这将在崇高的文字2和3两个工作。

+0

一个_outstanding_答案,谢谢! – trejder 2014-09-25 21:53:01

+0

@trejder很高兴我能帮到你! – MattDMo 2014-09-25 22:02:39