Surround with braces: move cursor before left brace

In PHPStorm (and other Jetbrains IDEs) there is the option (under Editor -> General -> Smart keys) called "Surround selection on typing quote or brace".

It would be so super amazing if on surrounding a selection with braces the cursor would move to before the left brace. That way we would be able to start typing the name of the function we want to apply to the selection right away, without having to press left arrow twice. This is the behaviour I would want 99.9% of the times I wrap something in braces. For me, this could be the default behaviour.



`return $this->price * 100;`

Select `$this->price * 100`

Type "("

Result: `return {CURSOR}($this->price * 100);`


Comment actions Permalink

Changing this behavior may be unexpected to other users. It's a valid feature request, but honestly I don't think we're going to do that. However, if you feel it'll gain many votes, it still makes sense to submit it.

Prior to doing that, please consider these two ways around:

  1. You can select the snippet right-to-left, so that after the parentheses are inserted, the only thing you have left to do is press Left once.
  2. You can utilize Live Templates for that, like $END$($SELECTION$).

And here's a link for creating a feature request:

Comment actions Permalink

Thanks for the reply! I have always used live templates for this, but still that requires you to be in a PHP context and it requires you to press some shortcuts to apply the live template. I will go for a feature request :).


Please sign in to leave a comment.