我是Sublime Text 2的新用户,目前主要用于Markdown/MultiMarkdown。在我的写作工作流中,我对所有斜体使用_underscore_配对,对所有粗体文本使用**double asterisk**配对。我使用了一些用于自动配对的基本代码,并在键入单个星号后将其配对为两个星号。这正是我想要的行为,但我一直无法让正常的配对-退格键函数工作。
对于其他自动显示的字符,如[],在键入开始字符后按退格键将删除两个成对的字符。但是,当我对这两个星号对中的一个进行退格时,它只删除了四个星号中的一个(只剩下***)。
有没有人知道这是否可能?为了获得额外的好处,我希望第二个键绑定代码片段(它允许您按tab键并跳到autopair的末尾)允许我按tab键到**TEXT**的末尾。
// Auto-pair double asterisks (type a single asterisk to invoke)
{ "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 }
]
},
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "**${0:$SELECTION}**"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "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 }
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "**$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^**", "match_all": true }
]
},
//Tab skips to end of autopaired characters
{ "keys": ["tab"], "command": "move", "args": {"by": "characters", "forward": true},
"context": [ { "key": "selection_empty", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^[\"'\\)\\}\\]\\_]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
{ "key": "has_next_field", "operator": "equal", "operand": false } ] },发布于 2013-01-11 00:10:46
*是正则表达式的特殊字符,因此您需要对其进行转义。backspace密钥应该如下所示:
"keys": ["backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\*$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true }
]注意preceding_text密钥regexp操作数中的\\*$和following_text密钥regexp操作数中的^\\*。无论如何,你必须按两次backspace键才能删除两个*:我认为不可能同时删除两个。
您需要的代码片段应该是这样的:
<snippet>
<content><![CDATA[
**${1:TEXT}** ${2:}
]]></content>
<tabTrigger>your_snippet</tabTrigger>
</snippet>您应该使用任何想要作为触发器的文本来更改your_snippet。
https://stackoverflow.com/questions/14260649
复制相似问题