Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortcut for creating braces in visual studio

many of time I have a if condition with just one line, like this:

if (true)
    // my single code

but sometimes, I want to expend my if condition to 2 or more codes, so I should use braces.

if (true)
{ 
    //do something
}

I want to know is there any shortcut for change first code to second one?

like image 457
Elahe Avatar asked Oct 31 '22 20:10

Elahe


1 Answers

You could create a code snippet that surrounds the selected text like this:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>curls</Title>
      <Description>Puts curly braces around the selected text.</Description>
      <Author>Erik Venema</Author>
      <SnippetTypes>
        <SnippetType>SurroundsWith</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Code Language="CSharp">
        <![CDATA[{
                $selected$
                $end$
                }]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

Save it as curls.snippet and import it in the code snippet manager.

After that you can use the snippet by selecting the text, press CTRL-K+CTRL-S and select the curls snippet.

like image 77
venerik Avatar answered Nov 12 '22 17:11

venerik