Sublime Text 2 - 双倍自动发送的角色

时间:2013-01-10 14:53:39

标签: markdown sublimetext2 multimarkdown

我是一个新的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 } ] },

1 个答案:

答案 0 :(得分: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 }
]

注意\\*$密钥正则表达式操作数中的preceding_text^\\*密钥正则表达式操作数中的following_text。 无论如何,您必须按backspace两次才能同时删除*:我认为不能同时删除这两个。

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

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

您应该将your_snippet更改为您想要的任何文本作为触发器。