visual-studio-codetextkey-bindingsbracketsvscode-keybinding

Any placeholder rules or keybinding commands to select a pair of characters in vscode?


{
    "key": "cmd+;",
    "command": "editor.action.insertSnippet",
    "when": "editorTextFocus && !editorReadonly",
    "args": { "snippet": "_${TM_SELECTED_TEXT}$1_$2" }
}

A block of code above manages to create a pair of underscores _ when I press cmd + ; on the vscode editor. I put this into the keybinding.json and it works fine. The problem is, the editor doesn't select the underscores just like a various type of brackets do such as (), [] and {}.

Let me explain more detail with .gif.

enter image description here

The .gif shows that the pair of square brackets [] are selected (grouped) with a small semi-transparent box after the [] are inserted. This eventually allows the users to delete a pair of brackets only 1 backspace if they don't need it anymore, giving them to save a lot of time to delete it.

I want to make my editor selects the pair of underscores _ like the square brackets [] on the above .gif shows. I believe there are some ways to resolve this but I can't find them anywhere else.

Any helps?


Solution

  • The .gif shows that the pair of square brackets [] are selected (grouped) with a small semi-transparent box after the [] are inserted. This eventually allows the users to delete a pair of brackets only 1 backspace if they don't need it anymore, giving them to save a lot of time to delete it.

    That's togglable via the editor.matchBrackets setting, and only works when a language support extension for the current editor's language mode registers such brackets in their language configuration.

    But as a user, you can also configure language brackets via the editor.language.brackets setting. Ex.

    "[plaintext]": {
        "editor.language.brackets": [
            ["_","_"],
        ],
    },
    

    For reasons I don't know, VS Code will accept this and add some bracket features like automatic closing "bracket" when typing the opening "bracket", and automatic closing "bracket" deletion on deleting the opening "bracket", but it won't do matching bracket outlines for underscores. If you're really concerned about that, you should raise an issue ticket.