Search code examples
visual-studiovisual-studio-2019code-snippets

Can a Visual Studio Snippet contain multiple shortcuts?


I've trawled through the code snippet documentation and can't find anything that says you can do this but thought I would ask anyway.

Consider the following snippet that adds a context menu TagHelper to a page:

<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>Context Menu</Title>
    <Author>UX</Author>
    <Shortcut>c:contextmenu</Shortcut>
    <Description>Markup snippet for a context menu</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Code Language="html">
      <![CDATA[<component:context-menu id="contextMenu">
            <context-menu-trigger>$end$</context-menu-trigger>
            <context-menu-content></context-menu-content>
        </component:context-menu>]]>
    </Code>
  </Snippet>
</CodeSnippet>

I've tried multiple shortcut tags:

<Shortcut>c:contextmenu</Shortcut>
<Shortcut>c:context-menu</Shortcut>

I've tried separating them with a comma:

<Shortcut>c:contextmenu,c:context-menu</Shortcut>

No joy, I assume it can't be done and that I would have to create two snippets; one for each shortcut?


Solution

  • this can be done. I found out by accident, but if you create multiple snippets with the same shortcut, when you use that shortcut you will get a pop-up giving you the option of which snippet do you want to run.