Vscode: Improve surround selection brackets behaviour

Created on 22 Sep 2017  路  10Comments  路  Source: microsoft/vscode

In most text editors and IDEs, typing after making a selection overwrites the selected text.

In VS Code, sometimes, when you try to type over a selection, the editor instead inserts next to or around the selected text.

For example, while editing a Typescript file here:

image

If I try to replace the selection with a double quote, this happens:

image

*duplicate editor-autoclosing feature-request

Most helpful comment

I don't want to turn off auto-closing brackets - it's useful most of the time.

PhpStorm has a similar auto-closing bracket behavior, but it only applies this behavior when it can meaningfully do so - e.g. when it doesn't result in garbled code.

All 10 comments

This is something special we do out of the box with certain characters (depends by programming language, but (, [, { or " are usual suspects).

It can be turned off via the not-so-obvious setting editor.autoClosingBrackets

I don't want to turn off auto-closing brackets - it's useful most of the time.

PhpStorm has a similar auto-closing bracket behavior, but it only applies this behavior when it can meaningfully do so - e.g. when it doesn't result in garbled code.

I see, I'm sorry, from your initial comment, it appeared that this is something new for you.

But now the ask is to continue having this behaviour, but make it syntactical aware. :+1:

PR welcome. The current implementation is language agnostic (e.g. it works the same in .txt files as in .ts files) and lives at:

I found myself wanting the reverse: I want to turn off closing brackets, but not selection surround. It's not clear why they are both bound to autoClosingBrackets.

I don't think it needs to be syntactically aware at all... it just needs to be aware of selections. When I have no text selected and type an opening bracket, yes, please give me the closing bracket. When I have a selection, however, I'd rather use a specific "surround with" command. Typing the opening bracket in this situation should replace the selection with the opening bracket. Long years of muscle memory with the various editors I use teaches me this is the behavior to expect. Nothing more frustrating than selecting a single-quote and trying to replace it with a double-quote and winding up with a double-quoted single-quote. LOL

I think people will want all 3 behaviors, so a string value instead of a Boolean would be appropriate for this setting.

For someone with a very long history of using Visual Studio (and it's predecessors), this is one of the more annoying behaviors in VSCode, and one for which there doesn't seem to be any work around other than "just build new muscle memory".

/duplicate #8536

Thanks for creating this issue! We figured it's covering the same as another one we already have. Thus, we closed this one as a duplicate. You can search for existing issues here. See also our issue reporting guidelines.

Happy Coding!

Is there any way to specify the array of chars I want to use to auto surround selection? I find that auto surrounding selection with asterisk or underscores would be great for markdown.

@ArturMroz That is currently not possible from a user level. It does make sense though, and I'd like to increase the configurability of autoClose in the next cycle. For a workaround, see #1307.

@JacksonKearl thanks for the suggestion. For what it's worth, I think vim-surround is the best solution for now (as long as you're using VSCodeVim).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

omidgolparvar picture omidgolparvar  路  3Comments

sirius1024 picture sirius1024  路  3Comments

borekb picture borekb  路  3Comments

philipgiuliani picture philipgiuliani  路  3Comments

vsccarl picture vsccarl  路  3Comments