Search code examples
visual-studio-codemarkdownbacktickspairingvs-code-settings

How to disable automatic pairing of triple backticks in VS Code in Markdown files while keeping other auto-pairings?


I've been enjoying the features of Visual Studio Code, but there's one specific behavior that has been counterproductive for me: the automatic pairing of triple backticks (```) in Markdown files.

To clarify, I'm not looking to disable all auto-pairings—just the triple backticks. Whenever I type a single backtick, VS Code automatically completes it with two additional backticks. This is time-consuming to remove manually each time and disrupts my workflow.

Here's an example of what happens:

Markdown - VS Code - Triple Backticks

Is there a way to disable this feature? If not, could someone guide me on how to disable this behavior in my own settings?

I've seen a similar question but it doesn't address my specific need to disable only the triple backticks while keeping other auto-pairings intact.

I've also created an issue on GitHub to address this, but I'm wondering if there's a workaround or setting that I've missed.

Is there a way to achieve this? If not, could someone guide me on how to modify this behavior in my settings?


I tried searching through the VS Code settings and keybinding options to find a way to disable the automatic pairing of triple backticks specifically, but found no such setting. I expected to find an option that allows me to turn off this particular auto-pairing while keeping others. What actually happens is that every time I type a single backtick, it auto-completes to triple backticks, which I then have to manually remove.

I've also created a GitHub issue to address this concern. Additionally, I've commented on the commits in the VS Code repository where this feature was recently implemented, but have yet to find a solution or workaround.

I was expecting to find an option within the VS Code settings that would allow me to disable the automatic pairing of triple backticks specifically, while keeping other auto-pairings active.


Solution

  • VS Code has added the autoClosingPairs api mentioned below. I have updated and released (v0.6.0) of my extension, Custom Language Properties It is now easy to disable backtick closing completions in markdown files. Here is a demo from the extension README:

    demo of extension modifying the markdown auto closing pairs completion in markdown files

    Note that I removed completion for both single and triple backticks in the example.


    You can also edit the language configuration file yourself. The only problem is that if it is ever updated by the vscode team you will have to re-do your changes.

    On a Windows system, the relevant file is located at:

    C:\Users\Mark\AppData\Local\Programs\Microsoft VS Code\resources\app\extensions\markdown-basics\language-configuration.json
    

    Here is what the autoClosingPairs key/value looks like for a markdown file:

      "autoClosingPairs": [
        {
          "open": "{",
          "close": "}"
        },
        {
          "open": "[",
          "close": "]"
        },
        {
          "open": "(",
          "close": ")"
        },
        {
          "open": "<",
          "close": ">",
          "notIn": [
            "string"
          ]
        },
        {
          "open": "`",       // consider deleting this as well
          "close": "`"
        },
        {
          "open": "```",    // delete this {} entry and save
          "close": "```"
        }
      ],
    

    You might want to make a back-up of that file first.

    I wrote an extension, Custom Language Properties, which has a command to show the language configuration file of the active editor:

    Custom Language Properties: Show language configuration for current editor
    

    It will open the relevant file (and the editor tab context menu Copy Path has its full path). In the editor which is opened you can edit and save the document. A reload is necessary for the edited language configuration file to take effect.

    And you will no longer get autoclosing of triple backticks. But there is sone issue, if you type 3 backticks in a row now vscode considers the third bactick to be part of an autoclosingPair itself and adds a fourth backtick...arg @#$.

    That can be solved by also deleting the

        {
          "open": "`",       // consider deleting this as well
          "close": "`"
        },
    

    making sure you don't leave any hanging commas in the json file.

    BTW, I hate the triple backtick completion too.

    You should also upvote this issue: LanguageConfiguration interface should expose autoClosingPairs which would also allow my extension and others to fix the problem easily. In fact, this already works but since the api is still proposed so it cannot be published. But in testing it works as expected.

    Demo is in a markdown file. Auto-closing works for {}()[]<> but not backticks because I excluded them in this extension's settings.

    demo in markdown file with backticks not being auto-closed