Vscode: Delete matching parentheses, brackets, or braces

Created on 21 Sep 2017  路  7Comments  路  Source: microsoft/vscode

  • VSCode Version: Code 1.16.1 (27492b6bf3acb0775d82d2f87b25a93490673c6d, 2017-09-14T16:38:23.027Z)
  • OS Version: Windows_NT x64 6.3.9600

    - Extensions: Extensions are disabled

Steps to Reproduce:

  1. Create a new file.
  2. Paste the following code: var foo = (1 + bar) + baz;.
  3. Position the cursor before the first (. It and its matching parenthesis should highlight.
  4. Hit the delete key.
  5. Only the first parenthesis is deleted.

It would be useful if the corresponding parenthesis, brace, or bracket were deleted when the targeted one was.

I see two ways to accomplish this:

  1. Add a shortcut for both backspace and delete that does the operation on the matching character.
  2. Automatically do the deletion. This could be an extension of the already-existing "editor.autoClosingBrackets" setting or (more likely) a new setting that governs this behavior.


Reproduces without extensions: Yes

editor-core feature-request

Most helpful comment

@jkyeung Or it could be done like Atom Editor does it. Bksp for regular bahaviour C-Bksp for matching parens behaviour

All 7 comments

This would be very useful, even if it was implemented as a keymappable action

This feature could be useful, but it could also be confusing and annoying, especially when editing code which already starts out with mismatched brackets. So it should absolutely be optional and off by default, or initially mapped to something other than plain Delete or Backspace.

Further, whether this new feature is active should be independent of whether editor.autoClosingBrackets is active.

@jkyeung Or it could be done like Atom Editor does it. Bksp for regular bahaviour C-Bksp for matching parens behaviour

There is a plugin Bracketeer, and then set vim key bindings.

    "vim.normalModeKeyBindingsNonRecursive": [
        {
            "before": ["<leader>", "p", "i"],
            "commands": ["bracketeer.removeBrackets"]
        },
        {
            "before": ["<leader>", "p", "'"],
            "commands": ["bracketeer.removeQuotes"]
        },
        {
            "before": ["<leader>", "p", "u"],
            "commands": ["bracketeer.changeBracketsTo"]
        },
    ],
    "vim.leader": "<space>"

I am interested in this as well.

I am also interested. And this feature is really needed. Note that Bracketeer did this according to language syntaxes and only supported a few languages. I do think a simple global one that could delete matching brackets even in plain text is more preferred.

This would save me so much time

Was this page helpful?
0 / 5 - 0 ratings