Search code examples
visual-studio-2010code-snippets

VS2010 Code Snippet Shortcut Not Showing


I've created a code snippet in VS2010. It isn't showing as a shortcut when I start typing. I've called it propnch.

It is available when I use Ctrl-K, Ctrk-X but when I just start typing prop... it isn't showing as an option.

Have I missed some kind of setting somewhere?

I had screen shots, but I don't think SO lets you upload any.

Edit: Screen Shots

I can see my snippet with Ctrl-K, Ctrl-X (its gone grey when I ctrl-PrtScn to take the screenshot)

enter image description here

But It doesn't appear with the other snippet shortcuts.

enter image description here

The snippet code is here (taken from this tutorial) and is in the "Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets" folder.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
    <Header>
        <Title>propnch</Title>
        <Shortcut>propnch</Shortcut>
        <Description>Code snippet for property and backing field and ensure 
  that it invokes INotifyPropertyChanigng and INotifyPropertyChanged</Description>
        <Author>Abhishek</Author>
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType>
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>type</ID>
                <ToolTip>Property type</ToolTip>
                <Default>int</Default>
            </Literal>
            <Literal>
                <ID>property</ID>
                <ToolTip>Property name</ToolTip>
                <Default>MyProperty</Default>
            </Literal>
            <Literal>
                <ID>field</ID>
                <ToolTip>The variable backing this property</ToolTip>
                <Default>myVar</Default>
            </Literal>
        </Declarations>
        <Code Language="csharp"><![CDATA[

private $type$ $field$;

public $type$ $property$
{
    get 
    { 
        return $field$;
    }
    set 
    { 
        this.OnPropertyChanging("$property$");
        $field$ = value;
        this.OnPropertyChanged("$property$");
    }
}
$end$]]>
        </Code>
    </Snippet>
</CodeSnippet>


Solution

  • It turns out this is a design flaw for the xml editor in VS2010. In the C# editor, you just type the shortcut and press 'tab'. IN the xml editor, it requires two more keystrokes.

    To quote from the documentation:

    To insert snippets using the shortcut name
        1. Position the cursor where you want to insert the XML snippet.
        2. Type < in the editor pane.
        3. Press ESC to close the IntelliSense complete word list.
        4. Type the shortcut name of the snippet, and press TAB to invoke the XML snippet.