问题:
通常,如果您想将代码保存为代码片段,则必须打开一些 xml 模板、研究标签等。参考 https://learn.microsoft.com/en-us/sql/ssms/scripting/add-transact-sql-snippets?view=sql-server-ver15
是否可以尽可能简化这个过程:即创建一个SurroundsWith
片段将通过片段代码包装选定的代码?
请尝试以下操作:
- 将此代码另存为create_new_snippet.snippet并通过代码片段管理器将其添加到您的 SSMS(Ctrl+K、Ctrl+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>
选择您的代码(您想要保存为片段)并调用Surround With...
片段(Edit\IntelliSense\Surround With...
Ctrl+K, Ctrl+S
)
如有必要,编辑参数(如标题、描述等)并另存为[YourSnippetName].snippet
进入您的代码片段文件夹。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)