VS2010 Code Snippet Shortcut Not Showing
Asked Answered
M

7

13

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>

Malvaceous answered 20/4, 2011 at 16:49 Comment(3)
Yo can add screen shots by clicking on the picture button just above the edit boxYapon
Can you post your .snippet? I've successfully replicated a snippet named propnch, and it works fine.Jinx
Hi, I've added the screen shots and snippet code.Malvaceous
I
7

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.
Idolla answered 10/9, 2012 at 11:21 Comment(3)
I don't understand why I have given this answer relating to XML intellisense, as the question concerns C# intellisense. 4-years-ago-me, what were you thinking?Idolla
Nevertheless, thank you, 4-years-ago-you! You saved me!Albion
@Idolla this was the only relevant answer that I found for my problem concerning the XML IntelliSense and Snippets. Thanks!Amateurism
M
4

According to screenshots, you have ReSharper installed and it overrides VS's IntelliSense behavior. You can either turn off Resharper's overriding or just add right in it a new LiveTemplate. More details here:

http://www.jetbrains.com/resharper/webhelp/Templates__Applying_Templates__Inserting_Imported_Code_Snippets.html

In my case I just added a new ReSharper template:

private $type$ _$loweredProperty$;

public $type$ $property$
{
    get { return _$loweredProperty$;}
    set 
    {
        if (_$loweredProperty$ == value) return;
        _$loweredProperty$ = value;
        OnPropertyChanged("$property$");
    }
}

adn it works even better: you have to type only two words - type and property name. The backing field will appear with lowered first letter. You must set "$loweredProperty$" to non-editable macros and point it to $property$. That's just a couple of clicks in Template editor.

Musselman answered 27/6, 2012 at 5:24 Comment(1)
Thanks that helped me a lot. Resharper hid the snippet testm (which creates a new test method). However now I have to type Ctrl + J everytime I want to use testm. Is there a way to add specific snippets back to intellisense?Soble
L
0

Too a sec to realize, but it's simple: you were missing the </CodeSnippets> at the end.

Latchkey answered 13/5, 2011 at 23:18 Comment(4)
I think this may have been a copy-paste error. I have the same issue with a couple of code snippets and the trailing tag is not the cause.Cobby
I tested this with the closing in my answer. It didn't work with text text you entered above, and with my correction it worked fine, so it does seem to have been the issue.Latchkey
I have the same issue with snippets made in the Snippet Editor, the closing tag is there, there must be another problemDipsomaniac
@grant - try asking a new question. as indicated, my answer does solve the problem in this case.Latchkey
H
0

CTRL +K+ X

or Right click on code page will show you the snippet

right click and start intellisense in Visualstudio

Handspring answered 5/1, 2013 at 18:9 Comment(0)
R
0

Go in Extensions and Updates of Visual Studio and then click on Online Tab and then in search type Bootstrap.

Install following Packs to enable intellisense

  1. Bootstrap Bundle
  2. Bootstrap Snippet Pack
Rhombohedral answered 12/5, 2016 at 10:16 Comment(0)
E
0

This may come a little bit late but if you are debugging a program CTRL K + CTRL X will not work. Stop debugging your program and try it again. it worked for me in VS 2013 and without Resharper.

Eleven answered 22/6, 2016 at 13:30 Comment(0)
B
0

If it is snippets for XML language it must be placed in next directory

C:\Users\%user%\Documents\Visual Studio 2015\Code Snippets\XML\My Xml Snippets\

For adding one of them to your document you must call snippet context menu by ctrl+K, ctrl+X. Your snippets will be in "My Xml Snippets"

Beeswing answered 29/6, 2016 at 7:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.