6

我正在尝试自动关闭*Markdown 文件中的星号 ( ) 字符。
我一直在查看所有语言设置文件,但没有找到任何可以用作示例的内容。我也尝试过编写一个片段,但发现它效率低下(它不会环绕选择)。

我四处搜索,发现 BracketHighlighter(它声称允许自定义自动关闭配对)但没有运气(通过 Package Control 安装,也重新启动)。

关于我应该从哪里开始或我做错了什么的任何想法?


解决方案(感谢@skuroda)

skuroda 的回答会很好 - 但是,我做了一些调整,我想将它们附加到他们的回答中:

{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "$0**"}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "preceding_text", "operator": "regex_contains", "operand": "\\*\\*", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }

    ]
}

**如果在两个前面的星号旁边按下星号键,则添加两个(例如,**|然后***|变为光标**|**所在|的位置。这对加粗文本有很大帮助。

4

3 回答 3

3

您可能需要对上下文进行一些调整,但这应该是一个开始。这是基于内置括号的自动配对键绑定。

{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*$0*"}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }

    ]
},
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*${0:$SELECTION}*"}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
    ]
},
{ "keys": ["*"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
    [
        { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
        { "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true },
        { "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
    ]
}
于 2013-04-16T00:18:37.687 回答
2

用这个

{ "keys": ["*"], "command": "insert_snippet", "args": {"name": "Packages/User/my-snippet.sublime-snippet" }}

现在去首选项>浏览包,然后用户文件夹创建一个文件

我的片段。崇高的片段

并在里面使用以下代码

<snippet><content><![CDATA[
*${0:$SELECTION}*
]]></content></snippet>

祝你好运

于 2015-05-16T04:28:46.507 回答
1
于 2018-08-19T15:48:54.103 回答