I am playing with Atom and I really like how I can select an expression and press Shift+9
to insert (
and )
outside it. This is convenient
To add curly brackets:
Just highlight your selection and press {
Same applies for square brackets[] and brackes ()
This is an in-built option in Visual Studio 2017. Go to Tools
-> Options
-> C / C++
-> Advanced
, then navigate within the options dialog as shown on the screenshot below.
Set the Enable Surround with Parentheses
option to True
.
This works for C++, but the process ought to be similar for other languages.
Once you click OK
, you should be able to automatically insert parentheses around any selected text by typing only the first (
You should check out a third party add-in like Resharper. They bundle a such abilities.
Resharper
There is another method noted by @Igor Zevaka.
Here: Any way to surround code block with Curly Braces {} in VS2008?
This allows you to create a snippet, and use a shortcut to use it.
Here is a quick and dirty snippet to do just that.
To Install:
Save the code as SurroundWithBraces.snippet into "\Visual Studio Version\Code Snippets\Visual C#\My Code Snippets"
To use:
Select block of text. Press Ctrl+K, Ctrl+S Chose My Code Snippets, braces
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>braces</Title> <Shortcut>braces</Shortcut> <Description>Code snippet to surround a block of code with braces</Description> <Author>Igor Zevaka</Author> <SnippetTypes> <SnippetType>Expansion</SnippetType> <SnippetType>SurroundsWith</SnippetType> </SnippetTypes> </Header> <Snippet> <Code Language="csharp"> <![CDATA[{ $selected$ $end$ }]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets>