VS2017如何实现选中代码块自动包裹括号/引号(无需扩展)
Hey there! I totally get why this behavior is annoying—coming from editors like Atom and VS Code that automatically wrap selected text when you type quotes or braces, VS2017's default overwrite feels like a step backward. Good news: you don't need Resharper or custom shortcuts to fix this—it's a built-in setting that's just probably disabled by default.
Here's how to turn it on:
- Open Visual Studio 2017, go to the top menu bar and select
Tools>Options - In the Options window, expand the
Text Editorsection, then navigate to the language you're working with (for your C# work, that'sC#>General) - Look for the checkbox labeled
Surround selected text on typing quotes or braces(it's under theAutomatic delimiter highlightingsection) - Check that box, then click
OKto save the changes
That's it! Now when you select a block of code and type quotes (", ') or braces ((), {}, []), VS2017 will wrap the selected text instead of overwriting it. If you ever use other languages in VS2017 (like Python, C++, or Go), you can repeat the same steps for their respective Text Editor > [Language] > General settings—this option exists for most supported languages.
Give it a test right away—select some code, type a quote, and you should see it wrap perfectly. No extensions, no shortcut tweaks required.
内容的提问来源于stack exchange,提问作者RPiAwesomeness

