custom code snippets in intellisense
Asked Answered
B

3

11

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.

Bibliotherapy answered 18/10, 2010 at 4:39 Comment(0)
E
10

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

Earmark answered 18/10, 2010 at 4:57 Comment(3)
for those wondering why these shortcuts aren't working in intellisense, try hitting tab twice rather than just once.Redan
All of my snippets already have the shortcut property, and typing the name and hitting tab works, but the snippets still do not appear in intellisense. It's really annoying because when i type the shortcut intellisense opens and highlights something else that has a similar name so i have to hit escape to close intellisense then hit tab to insert the snippet.Angkor
Do you have ReSharper? If so, check in 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.Petunia
P
6

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

Petunia answered 9/9, 2015 at 14:25 Comment(0)
U
0

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>

Unshapen answered 30/12, 2015 at 19:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.