Sublime Forum

Markdown fenced code snippet

#1

I recently updated to ST4 and refreshed my configuration files; I had been using the same ones for years. Unfortunately this has brought about a change that I would rather do without:

When I want to start a Markdown fenced code-block and I type two backticks, I immediately get prompted with a snippet that autocompletes the third backtick and prints “language” for selecting the highlighting. It also writes the ending backticks. See the attached screenshots.

I have looked through the config files but cannot find any way to turn this off. Can you please tell me what option I need to add to my user settings in order to accomplish this? Thanks.

0 Likes

#2

It’s a key binding in Markdown/Default.sublime-keymap

To override it you may want to place the following in your Packages/User/Default.sublime-keymap

    {
        "keys": ["`", "`"],
        "command": "",
        "context": [
            { "key": "setting.auto_match_enabled"},
            { "key": "selection_empty", "match_all": true },
            { "key": "selector", "operand": "text.html.markdown - markup.raw.code-fence - meta.code-fence" },
            { "key": "preceding_text", "operator": "regex_match", "operand": "^[ \t]*`?$" },
            { "key": "following_text", "operator": "regex_match", "operand": "^$" }
        ]
    },
2 Likes

#3

Thanks, that fixed the snippet problem. However, now when I type two backticks, the second one is not registered at all; I have to do 4 total keystrokes in order to get the three backticks.

0 Likes

#4

Maybe orverriding it with another snippet then?

    {
        "keys": ["`", "`"],
        "command": "insert_snippet",
        "args": {"contents": "`$0`"},
        "context": [
            { "key": "setting.auto_match_enabled"},
            { "key": "selection_empty", "match_all": true },
            { "key": "selector", "operand": "text.html.markdown - markup.raw.code-fence - meta.code-fence" },
            { "key": "preceding_text", "operator": "regex_match", "operand": "^[ \t]*`?$" },
            { "key": "following_text", "operator": "regex_match", "operand": "^$" }
        ]
    },

I can’t say how it works on Linux/Mac for sure. The backtick is a deadkey on my keyboard anyway, resulting in several inputs needed for it to be printed.

0 Likes

#5

Didn’t quite work, but closer. I’ll play around with it. Thanks!

0 Likes

#6

This drove me mad as well and this answer got me to this which worked for me.

    { "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0"} }

To the author of the feature, the problem (for me) is that I write Markdown just about everywhere (including here) and Sublime 4 is the only editor which auto-completes this for you. It breaks my muscle memory and makes me look extra carefully at the characters coming out of my keypresses, slowing me down sometimes significantly. Sometimes so much that I step away from what I was doing, venture out onto the interwebs in search of relief, to 20 minutes later type up a solution on a forum (such as this!).

0 Likes