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!).

1 Like

#7

thanks, looking for this for weeks. works good:

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

this snippet never fitted my behaviors. I have to manually correct the code generated every time.

meanwhile this is not a universal usage. I use Markdown in browsers, in VS Code, in Vim and suddenly it run into me in Sublime and generate surprises.

0 Likes

#8

This issue has been driving me crazy since I upgraded to ST4 and consider it a massive interference. I constantly have to stop and move around what I’m doing since my muscle memory (and how every single other application handling markdown handles it) is to type three back ticks, press ENTER, and type what I want in the code block.

ST devs: can you provide us a way to disable this behavior?

0 Likes

#9

@mottosso

Where are you applying that? in Packages/User/Default.sublime-keymap?

0 Likes

#10

You would pick Preferences > Key Bindings in the menu and enter it on the right.

Though it’s a bit of overkill to use insert_snippet for this if you’re not going to use any snippet features.

 { "keys": ["`"], "command": "insert", "args": {"characters": "`"} }

Would be more than enough since all it wants to do is insert a single character.

0 Likes

#11

The binding is removed from ST4114+.

0 Likes