-
1 添加一个“最小”的snippet
工具:Visual Studio 2013

新建文件,选择xml文件

将下面的代码粘贴入文件中
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>注释</Title>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA[]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

在<Code Language="">中,填入VB
在 Code 元素中的 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>
</Header>
<Snippet>
<Code Language="VB">
<![CDATA['=========================================================
'名 称:
'功 能:
'时 间:
'=========================================================]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

保存xml文件,以.snippet结尾

将编写好的代码段snippet文件导入到代码段管理器中。选择工具、断码段管理器。

点击导入,找到刚才保存的.snippet文件,然后打开。

将导入的代码段文件保存到我的代码片段中。

点击确定。

在VB工程代码区中,右键选择插入代码段。

选择我的代码片段。

选择注释。

创建的代码段成功插入文档中。

-
2 为snippet添加快捷键。
在刚才改动的title下,增加一对shortcut标签,内部加入你想要的快捷键。此处输入了qa。

插入代码段时,已经可以看到快捷键的提示。

输入qa,按下tab

插入成功!

补充加入默认编辑点和tab跳点:
<?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>qa</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>end</ID>
<Default></Default>
</Literal>
<Literal>
<ID>end1</ID>
<Default></Default>
</Literal>
</Declarations>
<Code Language="VB">
<![CDATA['=========================================================
'名 称:
'功 能:$end$
'时 间:$end1$
'=========================================================]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
网友评论