本文介绍了崇高文字2--双重自动配对字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm a newish Sublime Text 2 user, using it largely for Markdown/MultiMarkdown at this point. In my writing workflow, I use _underscore_ pairing for all italics, and **double asterisk** pairing for all bold text. I've taken some of the basic code for autpairing and gotten it to pair double asterisks after I type a single asterisks. This is the exact behavior I want, but I've been unable to get the normal pairing-backspace functions to work.

对于其他自动配对的字符,例如[],在键入开头字符后按退格键将删除两个配对的字符.但是当我退格这两个双星号之一时,它仅删除四个星号之一(留下 *** 给我).

With other autopaired characters, such as [], hitting backspace after typing the opening character will delete both paired characters. But when I backspace one of these double asterisk pairs, it deletes only one of the four asterisks (leaving me with ***).

有人知道这是否可能吗?为了获得奖励积分,我很乐意使用第二个绑定片段(可让您点击Tab并跳至自动配对的末尾),允许我将其跳至 ** TEXT ** 的末尾.

Any one know if this is possible? For bonus points, I'd love to have the second keybinding snippet (which allows you to hit tab and skip to the end of an autopair) allow me to tab to the end of **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 } ] },

推荐答案

* 是正则表达式的特殊字符,因此您需要对其进行转义. backspace 键应如下所示:

* is a special character for regular expression, so you need to escape it. The backspace key should be something like this:

"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 ,以删除两个 * :我认为不可能一次删除两个.

Notice the \\*$ in preceding_text key regexp operand, and ^\\* in following_text key regexp operand.Anyway, you'll have to hit backspace twice, to delete both *: I don't think it is possible to delete both at once.

您需要的代码段应如下所示:

The snippet you need should be something like this:

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

您应该使用要触发的任何文本更改 your_snippet .

You should change your_snippet with any text you want as a trigger.

这篇关于崇高文字2--双重自动配对字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:34