I have a code snippet string.Format(@"")
with a shortcut sf
that inserts the snippet and places the cursor in between the two double quotes. Really convenient. I can normally use it, of course, by just typing sf
and hitting tab twice:
However, I've just discovered that the shortcut doesn't work in all locations. For example, if I'm building this statement:
if(true) throw new FormatException() // <-- cursor is inside these parens
and I hit sf
, the shortcut does not appear in the intellisense menu, and if I hit Tab twice, it doesn't generate the snippet. Why?
I have tried searching for "C# code snippet shortcut sometimes doesn't work", "C# code snippet shortcut doesn't work", "visual studio code snippet sometimes doesn't work" among others, and I can't find anything useful about it.
EDIT: Here is the snippet definition:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>String.Format with @</Title>
<Author>Rory</Author>
<Description>
</Description>
<HelpUrl>
</HelpUrl>
<Shortcut>sf</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>anchor</ID>
<ToolTip>
</ToolTip>
<Default>
</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$" Kind="method body"><![CDATA[string.Format(@"$selected$$end$")]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
According to the docs the Kind attribute determines where you can use the snippet - you have specified "method body" and you should probably specify "any"
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