Surround code block with curly braces?

The quickest built-in shortcut in the Visual Studio scheme I can find is Ctrl+E+U, 7 (surround with..., then choose option 7 which is curly braces).

I don't see a shortcut for it in Visual Studio's keyboard options, so that may be the best you can get.


As an as an alternative to Patrick's answer (Ctrl+E, U, 7) you could also use the extended Alt+Enter -menu of ReSharper 9+.

Alt+Enter, UP, UP, Enter, or

Alt+Enter, "bl", Enter

Screen

Unfortunately, I don't know a way to bind this to a shorter hotkey.

But if this is really important to you, you could try AutoHotkey.


You do not need Resharper for this. You can use the "surround with" with a custom snippet.

Then you can select your text with Ctrl + K, Ctrl + S and select the snippet {} in the custom snippet. In order to create such a snippet :

  1. Create a ".snippet" file containing the content below
  2. Go to the snippet manager (Tools > Code Snippets Manager)
  3. Click import and select the file you just created

Use the following snippet :

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
 <CodeSnippet Format="1.0.0">
  <Header>
   <Title>{}</Title>
   <Shortcut>{}</Shortcut>
   <Description>Code snippet for {}</Description>
   <Author>Alexandre</Author>
   <SnippetTypes>
    <SnippetType>Expansion</SnippetType>
    <SnippetType>SurroundsWith</SnippetType>
   </SnippetTypes>
  </Header>
  <Snippet>
   <Code Language="csharp">
    <![CDATA[{ 
    $selected$ $end$ 
    }]]>
  </Code>
  </Snippet>
 </CodeSnippet>
</CodeSnippets>