Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I define custom "surround with" templates in Visual Studio 2008?

Can I define custom "surround with" templates in Visual Studio 2008?

like image 261
Piotr Owsiak Avatar asked Jul 23 '09 09:07

Piotr Owsiak


People also ask

How do I use code snippets in Visual Studio?

Code snippets can be accessed in the following general ways: On the menu bar, choose Edit > IntelliSense > Insert Snippet. From the right-click or context menu in the code editor, choose Snippet > Insert Snippet. From the keyboard, press Ctrl+K,Ctrl+X.

How do I create a snippet in Visual Studio?

With a code file open in the editor, choose Snippets > Insert Snippet from the right-click menu, then My Code Snippets. You should see a snippet named Square Root. Double-click it. The snippet code is inserted in the code file.

What is a snippet file?

Snippets files are written in JSON, support C-style comments, and can define an unlimited number of snippets. Snippets support most TextMate syntax for dynamic behavior, intelligently format whitespace based on the insertion context, and allow easy multiline editing.


1 Answers

Here you go, this is an example to set everything selected inside {}

In tools, codesnipet manager.

<?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>Sérgio</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Code Language="csharp"><![CDATA[{ 
        $selected$ $end$ 
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
like image 64
Sergio Avatar answered Oct 19 '22 12:10

Sergio