Visual Studio Update: Automatically Close Brackets and Quotes
Writing clean, error-free code often comes down to how well your text editor handles the little things. Whether you're working in Visual Studio or VS Code, one key improvement is the ability to close all brackets and quotes automatically. In his video on "Visual Studio Update: Automatically Close Brackets and Quotes", Tim Corey walks through a newly introduced setting in Visual Studio 2022 version 17.9 that simplifies this exact task.
This article follows Tim's step-by-step breakdown, explaining how to enable the feature, use it efficiently, and improve editing speed when working with code blocks, brackets, and quotes.
Introduction to Auto-Closing Brackets and Quotes
Tim begins the video by pointing out a common editing task in any code editor: wrapping text or code in quotes, parentheses, or curly braces. Whether you're formatting source code, isolating logic in a function, or preparing data for output, surrounding text properly is essential.
In Visual Studio 2022 v17.9, this task just got easier. With a simple change in settings, you can automatically wrap selected lines, variables, or HTML-like text in brackets or quotes by just typing the opening symbol. You don’t need to press a second key, use the mouse, or search the command palette—the text editor now handles it for you.
Demo: A Simple Math Example
To demonstrate the feature in context, Tim uses a small example involving math operations inside a code block. The logic includes a simple expression: 5 * 4 + 3. Tim runs the file to show the output—23. As he explains, this is due to the order of operations.
Next, Tim points out another part of the source code where a message is printed, but instead of printing the variable value, it just prints the variable name. He plans to update this part to better show the new bracket and quote behavior.
How to Turn On Auto-Wrapping in Visual Studio
This is where the tutorial gets practical. Tim explains that the automatically close brackets feature is disabled by default, so you have to enable it manually.
Here’s how you do it:
In Visual Studio, click Tools from the top menu.
Select Options.
In the Text Editor section, go to General.
Under Display, find and check the option labeled\ “Automatically surround selections when typing quotes or brackets.”
- Press OK to apply.
This setting changes how Visual Studio behaves when typing symbols like (, {, ", ', and others. Tim emphasizes that Microsoft has left this feature off by default so as not to disrupt existing editing workflows. But once enabled, it becomes a powerful way to speed up coding.
Changing Code Context with Auto-Wrapping
With the feature enabled, Tim demonstrates how to restructure code more efficiently. He selects 4 + 3 from the expression and types the open parenthesis (. The editor immediately surrounds the selection with (4 + 3)—without needing to type the closing bracket.
This changes the result of the equation from 23 to 35, because now the context of the expression shifts due to parentheses. Tim uses this to explain how the cursor position, keyboard input, and smart editing features can dynamically enhance the coding experience.
He points out that this works not just with parentheses, but with a variety of brackets, making it ideal for managing complex code blocks, logic in functions, or even tags in HTML documents.
Wrapping Variables, Text, and Comments with Ease
Next, Tim expands the demo with a variety of wrapping examples:
He selects the word result and types {. It becomes {result}—perfect for string interpolation or data placeholders.
Highlighting the word “math” and pressing ' wraps it in single quotes: 'math'.
- Highlighting an entire line and pressing " wraps the whole sentence in double quotes: "The answer to the math problem is...".
Tim even shows wrapping text with square brackets [], angle brackets <>, and curly braces {}. These tools are useful whether you're working with C#, HTML, JSON, or even writing comments or custom regions in code.
If you’ve ever wished for a quicker way to insert paired symbols, especially across multiple lines, this feature brings your editor one step closer to an intuitive writing assistant.
Quick Results: Keyboard-Driven Formatting
Tim concludes by rerunning the code. With all changes made, the output now says:
“The answer to the ‘math’ problem is 35”
Thanks to Visual Studio’s ability to automatically surround selected text, Tim’s small code adjustments were faster, easier, and more reliable. He notes that this enhancement turns Visual Studio into an even better text editor—something closer to the flexibility of VS Code with keyboard shortcut support and command-like automation.
While Tim’s demo is in Visual Studio, users of Visual Studio Code (VS Code) can achieve similar results using features like editor.autoSurround in the settings or by assigning custom keyboard shortcuts via the command palette.
Closing Brackets and More: Cross-Platform Notes
Though Tim’s tutorial is focused on Windows, these concepts apply broadly. If you're using Visual Studio Code on Mac or Linux, you can:
Press Ctrl+K Ctrl+S to open the keyboard shortcut window.
Use Cmd on macOS instead of Ctrl.
Set up key bindings to collapse or unfold code regions.
Access settings like editor.autoSurround to auto-wrap your selections with quotes or brackets.
- Use Shift+Alt+A to comment code blocks or Ctrl+/ for line comments, depending on your OS.
These commands allow you to toggle and fold parts of your code or adjust brackets and quotes automatically—streamlining your editing workflow no matter the platform.
Conclusion
Tim Corey’s video provides a focused tutorial on how to improve coding speed in Visual Studio by enabling a single setting: automatically surround selections when typing quotes or brackets. Whether you’re working in VS Code or Visual Studio, learning how to quickly close all brackets, wrap lines, or structure logic without breaking focus from the keyboard is a skill worth mastering.
For developers looking to write clean, structured source code quickly—without reaching for the mouse—this is a powerful feature to activate. And if you’re someone who uses VS Code, consider exploring its similar auto-wrapping and folding capabilities via the command palette and keyboard shortcuts.
Do check out Tim Corey’s YouTube channel for more practical tutorials and updates on Visual Studio, .NET development, and productivity tips for developers.
