在SSMS中创建代码段的代码段 [英] Snippet to create Snippet in SSMS

查看:113
本文介绍了在SSMS中创建代码段的代码段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:
通常,如果要将代码另存为摘要,则必须打开一些xml模板,调查标签等。


Problem: Usually, if you want to save your code as a snippet, you have to open some xml template, investigate tags etc. Reference

Is it possible to simplify this process as much as possible: i.e. create a SurroundsWith snippet that will wrap selected code by snippet code?

解决方案

Please try following:

  1. Save this code as a create_new_snippet.snippet and add it to your SSMS through code snippet manager (Ctrl+K, Ctrk+B)

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>Create_new_snippet</Title>
            <Shortcut></Shortcut>
            <Description>Snippet to create a snippet</Description>
            <Author>Denis Sipchenko</Author>
            <SnippetTypes>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal> <ID>Title</ID>        <Default>NewSnippetTitle</Default>         <ToolTip>NewSnippetTitle</ToolTip>                   </Literal>
                <Literal> <ID>Description</ID>  <Default>NewSnippetDescription</Default>   <ToolTip>NewSnippetDescription</ToolTip>             </Literal>
                <Literal> <ID>Author</ID>       <Default>Unsung Hero</Default>             <ToolTip>NewSnippetAuthor</ToolTip>                  </Literal>
                <Literal> <ID>SnippetType</ID>  <Default>SurroundsWith</Default>           <ToolTip>SurroundsWith OR Expansion</ToolTip>                  </Literal>
                <Literal> <ID>CodeComment</ID>  <Default>-- Sorry. I was too lazy to write some usefull comment here</Default>         <ToolTip>Comment for you code</ToolTip>                  </Literal>                
            </Declarations>
            <Code Language="sql"
                Delimiter="`">
                <![CDATA[<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>`Title`</Title>    <!--`Title`.snippet -copy/paste for filename-->
            <Shortcut></Shortcut>
            <Description>`Description`</Description>
            <Author>`Author`</Author>
            <SnippetTypes>
                <SnippetType>`SnippetType`</SnippetType>    <!--SurroundsWith/Expansion-->
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal> <ID></ID>     <Default></Default>         <ToolTip></ToolTip>                   </Literal>
            </Declarations>
            <Code Language="SQL">
                <![CDATA[`CodeComment`
$selected$`selected`$end$`end`
]]`fake`>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

  1. Select your code (that you want to save as a snippet) and call Surround With... snippet (Edit\IntelliSense\Surround With... Ctrl+K, Ctrl+S)

  2. Edit parameters if necessary (as Title, Description etc...) and save as [YourSnippetName].snippet into your snippet folder.

这篇关于在SSMS中创建代码段的代码段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆