Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove surrounding quotes/parenthesis/brackets/etc on IntelliJ

Is there a way on IntelliJ to remove surrounding parenthesis, brackets, quotes, etc? For example, if I have:

"string"

Is there any way to remove the matching quotes and get this?

string
like image 589
Daniel C. Sobral Avatar asked May 28 '15 22:05

Daniel C. Sobral


3 Answers

Not directly, but the following replace expression (ctrl+R, tick Regex) might help:

Search for: "(.*)"

replace with: $1

like image 185
vikingsteve Avatar answered Nov 01 '22 04:11

vikingsteve


Edit: I found an easier way (plugin code with regex left below for nostalgia)

Webstorm has extend selection and shrink selection on mac they are bound to alt-upArrow and alt-downArrow

You can use extend selection to select the content and the quotes/braces/parens, then record a macro (i called mine unwrap) and perform the following actions:

  1. shrink selection once
  2. copy
  3. extend selection once
  4. paste

then you can save the macro and add a key binding.

Any time you want to unwrap something, you can just extend the selection until it includes the outer braces, then hit your hotkey and it will replace the selection including the braces with their inner contents.


I made a mini-plugin,

which i install/code using live-plugin.

It relies on this Regex:

[\["'({](.+)['"})\]]

The Regex will also often work in the Search/Replace function in webstorm
(with Regex and In Selection checked), but it fails in mysterious cases:

  • eg. single quotes that are inside parens - even if the outer parens are not in the selection to be considered
like image 4
gotjosh Avatar answered Nov 01 '22 05:11

gotjosh


IDEA have an action to go to matching brace.
You can create macro with something like: goto next brace - delete one char - goto prev brace - delete one more char.
And then set kb shortcut to this macro.

like image 2
guai Avatar answered Nov 01 '22 05:11

guai