0

我是一个新的 Sublime Text 2 用户,此时主要将它用于 Markdown/MultiMarkdown。在我的写作工作流程中,我_underscore_对所有斜体使用配对,**double asterisk**对所有粗体文本使用配对。我已经采用了一些基本的自动配对代码,并在我输入一个星号后让它配对双星号。这是我想要的确切行为,但我无法让正常的配对退格功能工作。

对于其他自动配对字符,例如 [],在输入开始字符后按退格键将删除两个配对字符。但是当我退格其中一个双星号对时,它只会删除四个星号中的一个(让我留下***)。

有人知道这是否可能吗?对于加分,我希望有第二个键绑定片段(它允许您点击制表符并跳到自动配对的末尾)让我可以制表符到**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 } ] },
4

1 回答 1

0

*是正则表达式的特殊字符,所以需要转义。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 }
]

注意\\*$inpreceding_text键正则表达式操作数和^\\*infollowing_text键正则表达式操作数。无论如何,您必须点击backspace两次才能删除两者*:我认为不可能同时删除两者。

您需要的代码段应该是这样的:

<snippet>
    <content><![CDATA[
**${1:TEXT}** ${2:}
]]></content>
    <tabTrigger>your_snippet</tabTrigger>
</snippet>

您应该your_snippet使用您想要作为触发器的任何文本进行更改。

于 2013-01-10T16:10:46.417 回答