Automatically close custom brackets in Sublime Text

I am trying to automatically close the asterisk ( * ) character in Markdown files.
I have looked through all the language settings files and I am not using anything to be used as an example. I also tried to write a fragment, but found it ineffective (it does not wrap around the choice).

I searched around and found BracketHighlighter (which claims to allow customizable auto-close pairs), but no luck (installed via the Control Package, also rebooted).

Any ideas on where I should start or what I am doing wrong?


Solution (thanks @skuroda)

skuroda's answer will be fine, but I made a few tweaks that I would like to add to their answer:

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

This adds two ** if the asterisk key is pressed next to the two previous asterisks (for example, **| , and then ***| becomes **|** , where | is the cursor. This helps a lot with the boldness of the text.

+4
source share
2 answers

You may need to adjust the context a bit, but this should be the beginning. This is based on the key pairing of the automatic pair for inline brackets.

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

Use this

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

go to Preferences> Package Overview and then User Folder Create File

my snippet.sublime snippet

and use the following code inside

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

Luck

+1
source

All Articles