Sabirul Mostofa
Sabirul Mostofa

Reputation: 61

VSCode insert double round brackets around a selection or a single Word

How could I insert double brackets like this around selected text with a keyboard shortcut(ctrl+alt+d for example):

((Selected Text))

I know that, its possible to surround the selection with brackets by selecting a text and pressing ((.

How could I do it with a keybinding around a single word on the cursor position without selecting the word?

Upvotes: 1

Views: 4148

Answers (2)

Sabirul Mostofa
Sabirul Mostofa

Reputation: 61

Pressing

ctrl+d

selects the word under cursor, then you could press double brackets "((" to insert brackets around the word

Upvotes: 1

rioV8
rioV8

Reputation: 28673

You can use the extension multi-command

Add the following keybindings

  {
    "key": "ctrl+alt+d",
    "when": "editorTextFocus && !editorHasSelection",
    "command": "extension.multiCommand.execute",
    "args": { 
      "sequence": [
        "editor.action.addSelectionToNextFindMatch",
        { "command": "type", "args": { "text": "((" } }
      ]
    }
  },
  {
    "key": "ctrl+alt+d",
    "when": "editorTextFocus && editorHasSelection",
    "command": "extension.multiCommand.execute",
    "args": { 
      "sequence": [
        { "command": "type", "args": { "text": "((" } }
      ]
    }
  }

It also works with multi cursors.

Edit Marks comment on using "(("

Upvotes: 1

Related Questions