开发者

How do you use an alternative shortcut defined in a Visual Studio code snippet?

This may sound like a stupid question but I can't seem to find an answer. For example, take a look at the default div snippet that ships with Visual Studio 2010:

<CodeSnippet Format="1.1.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <Header>
    <Title>div</Title>
    <Author>Microsoft Corporation</Author>
    <Shortcut>div</Shortcut>
    <AlternativeShortcuts>
      <Shortcut>p</Shortcut>
      <Shortcut>h1</Shortcut>
      <Shortcut>h2</Shortcut>
      <Shortcut>h3</Shortcut>
      <Shortcut>h4</Shortcut>
      <Shortcut>h5</Shortcut>
      <Shortcut>h6</Shortcut>
      <Shortcut>blockquote</Shortcut>
      <Shortcut>pre</Shortcut>
      <Shortcut>address</Shortcut>
      <Shortcut>center</Shortcut>
      <Shortcut>noscript</Shortcut>
    </AlternativeShortcuts>
    <Description>Markup snippet for a block element</Description>
    <SnippetTypes>
      <SnippetType>Expansion</SnippetType>
      <SnippetType>SurroundsWith</SnippetType>
    </SnippetTypes>
  </Header>
  <Snippet>
    <Code Language="html"><![CDATA[<$shortcut$>$selected$$end$</$shortcut$>]]></Code>
  </Snippet>
</CodeSnippet>

How would I use the alternative p shortcut? In IntelliSense, none of the alternatives are available. First of all, I've tried Surround With > HTML > p but since that's not a valid IntelliSense option, it defaults to surrounding with an a tag.

Additionally, I've tried Surround With > HTML > divp, div p, div-p, div:p among others and nothing works, it just defaults to div (and note the first option I wanted to try was div > p but the snippet selector won't allow > as input).

Does anyone know how开发者_StackOverflow社区 to use this feature?


Accepting Hans' comment as the answer.


It's now documented. AlternativeShortcuts is used for intellisense when you start typing tags. Still no use with 'Surround With' even in VS 2013.

Quote from the link above:

Notice that the Alternative Shortcuts list includes other HTML elements such as p, h1, h2, and so on. This tells you that the same snippet is invoked by using the shortcuts <div, <p, <h1, and so on, because the corresponding HTML elements all use a similar pattern. Therefore, these elements are grouped together in the Code Snippets Manager.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜