May 11th, 2023

Surround selection experiment

Mads Kristensen
Principal Product Manager

You want to quickly select some text and surround it with quotation marks. So, you select your text and hit the quotation mark key on your keyboard, only to find that the selected text now has been replaced by a single “. What you hoped would happen was that the selected text would be surrounded by an opening and closing quotation mark like in the animation below. Let’s do something to fix this.

Image Surrounder2

In this experiment, we want to test if we can create a general feature for all languages that makes it easy to surround the selection. In fact, multiple developers have requested this feature, so remember to vote for it if you agree.

Our hypothesis is that a feature like this is language agnostic and doesn’t need to be customized per language. But we need your help to help test that hypothesis and, potentially, help improve the feature design. We’ve created an extension for Visual Studio called Surrounder that we’ll be using for this experiment.

The extension is very simple to use. Any time you have a selection and type one of the supported characters, the selection will be surrounded by that character and its closing equivalent, as shown in this table:

Opening Closing
` `
( )
[ ]
{ }
< >

 

To participate in this experiment, install the Surrounder extension and let us know how it works for you. Either by commenting in this blog post, or by opening issues or pull requests on the GitHub repo.

There is currently an open feature request for us to implement this behavior in Visual Studio, so make sure to go vote for it.

Author

Mads Kristensen
Principal Product Manager

Mads Kristensen is a principal program manager on the Visual Studio team and has published over 150 free Visual Studio extensions. He blogs about anything related to Visual Studio and can often be found hosting various shows on the Visual Studio YouTube channel..

15 comments

Discussion is closed. Login to edit/delete existing comments.

  • Joshua Laquai

    How is this an “experiment” when VSCode has had this feature since the beginning of time and!?
    And as @reduckted already mentioned, AutoSurround has been available for VS for ages AND it’s so far ahead of… whatever this is.
    Stop trying. Accept you’re years late to the party and stop trying.

    • Mads KristensenMicrosoft employee Author

      From the third paragraph:

      > Our hypothesis is that a feature like this is language agnostic and doesn’t need to be customized per language. But we need your help to help test that hypothesis and, potentially, help improve the feature design.

  • Eli Black

    As long as there’s a setting to enable/disable this, I’m all for it! 🙂

    I’m not a fan of this feature, but I know this has become standard in most other editors, so making it be the default in VS probably makes sense, too! 🙂

  • Andreas Saurwein

    Great feature - at least 10 free extensions already do that. Is it really required to add this now to VS? It feels like VS is trying to catch up with VS Code. Adding more and more features that break existing ones.

    Besides, this kind of features have a negative influence on the extension economy. There are many extensions that are cheap but lost their right to exist because VS after 20 years finally can do...

    Read more
    • Mads KristensenMicrosoft employee Author

      Features first found in extensions sometimes become industry standard in editors and IDEs. At this point, there is an expectation from users that these features are found natively in Visual Studio or whatever their tool of choice might be. We don’t want to discourage extension authors (believe me, I’m one myself), but expectations, use cases, and competitive landscapes change over time, and we must all adapt.

  • Viacheslav Ivanov

    Nice thing!

    I’m expecting an escaped double quote inside a string literal in C# so for me this feature should be language specific:

    var text = $"User {userName} not found.";

    “{userName}” is selected and double quote pressed

    var text = $"User \"{userName}\" not found.";

    Instead, it would make sense to allow pressing other characters, including backslash, while Alt or Shift pressed, so the user can type escape symbols.

  • Sergey Benzenko · Edited

    IDK, maybe it's just me, but this feature more often than not just irriates me rather than helps.
    Specifically when I copy and paste SQL with parameters from web code in order to test it, and want to replace parameters with actual values in quotes. So I select the parameter name and instead of replacing it with input, it put it in quotes which is not what I expect.

    I'd prefer it via <code> rather than...

    Read more
  • Michael Taylor · Edited

    If the surround behavior is "simple" then I can see it being language agnostic as you literally just insert a character before and after the selection range. But I don't know how terribly useful that is. A "smart" selection may be somewhat consistent between languages but I still think it needs some language knowledge to know how to proceed.

    For example in C# if I'm surrounding text with double quotes and it is already in...

    Read more
  • Lumen Papulus

    > So, you select your text and hit the quotation mark key on your keyboard, only to find that the selected text now has been replaced by a single “

    No, we don’t, cause we use ReSharper!

    • Andreas Saurwein

      Or any other extension we payed for that does it for us since … ever.

  • Evgeny Vrublevsky (VEG) · Edited

    That’s a very irritating “feature”, I always look how to disable such stuff. If you selected some text and started to type anything else, it is expected that the selected text is replaced. Don’t need to add any magic here.

    • Fernando Borrego Polo

      Same here. If they do that, I will have to relearn years of using text editors and have to first delete the text and then start typing the quote I wanted to write in the first place.

  • reduckted

    > Our hypothesis is that a feature like this is language agnostic and doesn’t need to be customized per language.

    Weird. I wonder why VS Code uses language-specific character pairs.

    Anyway, AutoSurround already does this and has virtually the same behavior as VS Code, including specific character pairs for each language.

  • MgSam

    This sounds like a cool feature. MS Word would benefit from this just as much as Visual Studio!