Chris McGrath
Chris McGrath

Reputation: 1757

custom code snippets in intellisense

I've started exporting some of my frequently used blocks of code to custom snippets. Is there a way to get these to show up in IntelliSense and not have to use the snippet browser from the context menu or snippet manager?

At first, I thought this was related to ReSharper, but they still don't show up when I disable the ReSharper IntelliSense.

It would be nice to be able to just use the snippet shortcut instead of using the browser.

Upvotes: 11

Views: 5433

Answers (3)

sharad shrestha
sharad shrestha

Reputation: 188

If you are still not seeing the shortcut, but you have ReSharper then check in Resharper > Options > IntelliSense > General. If you have ReSharper radio button selected, then your intellisense created in VS [shortcut] will not appear. Change that to Visual Studio or alternatively create intellisense in ReSharper

Upvotes: 6

Akash Gutha
Akash Gutha

Reputation: 599

Here is a brief description on how to create your own Snippets in Visual Studio with the 'shortcut' tag.

using a Code Snippet for INotifyPropertyChanged

This is the tag that is required to get the shortcut functionality.

 <Shortcut>switch</Shortcut> 

Here is a snippet for switch which is inbuilt into VS

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
    <Header>
        <Title>switch</Title> 
        <Shortcut>switch</Shortcut> 
        <Description>Code snippet for switch statement</Description> 
        <Author>Microsoft Corporation</Author> 
        <SnippetTypes>
            <SnippetType>Expansion</SnippetType> 
        </SnippetTypes>
    </Header>
    <Snippet>
        <Declarations>
            <Literal>
                <ID>expression</ID> 
                <ToolTip>Expression to switch on</ToolTip> 
                <Default>switch_on</Default> 
            </Literal>
            <Literal Editable="false">
                <ID>cases</ID> 
                <Function>GenerateSwitchCases($expression$)</Function> 
                <Default>default:</Default> 
            </Literal>
        </Declarations>
        <Code Language="csharp">
            <![CDATA[
                switch ($expression$)
                {
                    $cases$
                }
            ]]>
        </Code>
    </Snippet>
</CodeSnippet>

Upvotes: 0

Prince Ashitaka
Prince Ashitaka

Reputation: 8773

You need to set the ShortCut property like <Shortcut>slpropdp</Shortcut>. The best way to learn editing this, just check any of the already existing codesnippets. By, going to Tools -> Code snippet manager. Select any code snippet, the location of the code snippet will be available at the top location bar

Upvotes: 10

Related Questions