I've made a custom snippet for use in Visual Studio. In VS2013, it worked as expected, but since using it in VS2015 (Community Edition) it's been inserting an extra newline before the code (right when I press tab/enter the second time).
This seems to only be a problem with the custom snippet (the built-in ones work fine). Anyone know what could be causing this? It's very annoying.
As a side note, this only happens if I'm activating the snippet on an empty line of code. If I do it after existing code, the newline isn't inserted. Unfortunately, the snippet is a statement, so this doesn't help much.
Here's the snippet, copied almost entirely from the VS sample:
<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet"> <CodeSnippet Format="1.0.0"> <!-- The header contains information describing the snippet. --> <Header> <!-- The Title of the snippet, this will be shown in the snippets manager. --> <Title>Insert Field Add</Title> <!-- The description of the snippet. --> <Description>Inserts a basic field add for a DataObject</Description> <!-- The author of the snippet. --> <Author>Thomas Price</Author> <!-- The set of characters that must be keyed in to insert the snippet. --> <Shortcut>fadd</Shortcut> <!-- The set of snippet types we're dealing with - either Expansion or --> <SnippetTypes> <SnippetType>Expansion</SnippetType> </SnippetTypes> </Header> <!-- Now we have the snippet itself. --> <Snippet> <!-- Create any declarations that we use in the snippet. --> <Declarations> <Literal> <ID>FieldName</ID> <ToolTip>Enter the field name</ToolTip> <Default>field</Default> </Literal> </Declarations> <!-- Sepecify the code language and the actual snippet content. --> <Code Language="CSharp" Kind="any"> <![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");]]> </Code> </Snippet> </CodeSnippet>
To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.
Code snippets are ready-made snippets of code you can quickly insert into your code. For example, the for code snippet creates an empty for loop. Some code snippets are surround-with code snippets, which enable you to select lines of code, and then choose a code snippet which incorporates the selected lines of code.
You can prevent the preceding newline by placing $end$ somewhere in your snippet text. Example:
<![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");$end$]]>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With