Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace matching brackets for parenthesis vscode

Is there a way to quickly replace matching brackets for matching parenthesis (or any other opening/closing characters) in vscode?

Something like ctrl+d but for matching brackets, parenthesis and such.

I'm currently replacing traditional JavaScript function definitions (redux action creators) for arrow functions, also I'm using airbnb rules in eslint in which the rule arrow-body-style needs to move the returning value immediately after the => and because most action creators return an object literal it needs to be surrounded by parenthesis, that's why I need a mechanism to make the replacements easy.

I'm trying to change.

export function hideServerErrors() {
 return {
  type: HIDE_SERVER_ERRORS,
 };
}

to

export const hideServerErrors = () => ({
 type: HIDE_SERVER_ERRORS,
});
like image 801
Rodrirokr Avatar asked May 22 '26 14:05

Rodrirokr


1 Answers

Remove brackets

Since vscode v1.77 (april 2023) there is build in action that can help in this case.

Remove Brackets
editor.action.removeBrackets

It deletes both matching parentheses by one hotkey.

By default bound to Ctrl+Alt+Backspace.

Changing brackets with this command

  1. Put cursor to bracket you want to change
  2. Use editor.action.selectToBracket (assign keybinding, e.g. Ctrl+Shift+Alt+\ and press it, or search for this action in Ctrl+Shift+P menu) to select content inside brackets.
  3. Press new bracket (that will automatically surround selected content)
  4. Put cursor to old bracket again
  5. Press Ctrl+Alt+Backspace to delete old brackets.
like image 57
Hacker1337 Avatar answered May 26 '26 14:05

Hacker1337



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!