sublimetext2 - Sublime Text 中的自定义括号自动关闭

标签 sublimetext2 auto-close

我正在尝试自动关闭 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 }

    ]
}

其中增加了两个 **如果在前面两个星号旁边按下星号键(例如 **|,则 ***| 变为 **|**,其中 | 是光标。这对加粗文本有很大帮助。

最佳答案

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

{ "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 }
    ]
}

关于sublimetext2 - Sublime Text 中的自定义括号自动关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16025592/

相关文章:

python - wxPython 中带有自动关闭计时器的 wxMessageBox

c# - 打开多个 MessageBox 实例并在几秒后自动关闭

geany - Geany IDE 是否有自动关闭大括号插件?

vim - Vim 自动关闭大引号

google-chrome - Chrome 扩展开发 : auto close the notification box

applescript - 从 SublimeText 运行 AppleScript 时出现问题

sublimetext2 - 印地语和 Sublime Text

css - 有没有比在 SublimeText2 中编辑 HTML/CSS 然后在浏览器中 F5/刷新以查看更改更好的工作流程?

sublimetext2 - Sublime Text 中这个奇怪的空格是什么?

sublimetext2 - Sublime Text 插件 - 向区域添加范围(或颜色)