visual-studio-codekey-bindingsvscode-snippets

In visual studio code how to keybind in the combination [alt + ctrl + '] the key [`]?


In visual studio code

How to keybind in the combination alt + ctrl + ' to output a backtick ` as a quote?

I'm searching the specific command to put in the keybindings.json

{
    "key": "alt+ctrl+\'",
    "command": "????????????command?????????????",
    "when": "editorTextFocus && !editorReadonly"
}

Solution

  • I assume you want Ctrl+Alt+' to output a backtick `

     {
        "key": "ctrl+alt+'",
    
        // "command": "type",       // normally this would work
        // "args": {"text":"`"},
    
        // "command":  "editor.action.insertSnippet",  // this outs just one backtick
        // "args": {
        //   "snippet": "`"
        // },
    
      "command":  "editor.action.insertSnippet",
      "args": {
        "snippet": "`$TM_SELECTED_TEXT`"   // use this to wrap selected text with backticks
      },
    
        "when": "editorTextFocus && !editorReadonly"
     },
    

    Normally, the type command is what you would use here, but since it outputs a backtick vscode automatically adds another - just like typing one " outputs two. Unless you set your Editor > Auto Closing Quotes setting to never, but that will affect all quotes, not just backticks.

    So if you only want one backtick, use the insertSnippet command version - it only outputs one backtick.