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