0

In SSMS I would like to use shortcuts for code snippets, just like in Visual Studio:

type 'shortcut'; hit TAB -> snippet expanded

In SSMS I need to CTRL+K, CTRL+X, mouse, mouse, find, go back, find, mouse. This is not a shortcut, nothing "short" about it.

I've added this sample snippet to my list of snippets:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Transaction</Title>
      <Author />
      <Description>Transaction wrapper</Description>
      <HelpUrl />
      <SnippetTypes />
      <Keywords />
      <Shortcut>tra</Shortcut>
    </Header>
    <Snippet>
      <References />
      <Imports />
      <Declarations>
        <Literal Editable="true">
          <ID>TSQL</ID>
          <Type />
          <ToolTip />
          <Default>TSQL</Default>
          <Function />
        </Literal>
      </Declarations>
      <Code Language="SQL"><![CDATA[
BEGIN TRANSACTION TRAN1
$TSQL$
ROLLBACK TRANSACTION TRAN1]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>

I can find it via CTRL+K, CTRL+X, but I'm unable to invoke it by tra + TAB shortcut. Am I missing something? Can SSMS even do this?

I'm using SSMS v13.0.16100.1, but database is SQL Server 2014.

2

No, while the XML schema contains a shortcut element, the fact is that proper shortcut support was never implemented (several of the other elements are not visible outside the XML, either). The following Connect item was closed as "Won't Fix" back in 2013:

You may be able to raise awareness of this issue on another place where the SSMS team is paying attention: trello. But I'll warn you: even with an accelerated dev and release cycle, they have a lot on their plates, and I'm not sure this could make any significant dent into the top, say, 50 enhancements.

(Personally, I haven't found that I've need to use my mouse to insert snippets - all that is needed is keystrokes. Obviously YMMV.)

  • Oh, well... I suspected this is going to be the case. Thanks for confirming it. – trailmax Mar 7 '17 at 13:39
  • Have you looked at custom templates as an alternative? These have been in SSMS (and Query Analyser) long before snippets. Add your own templates, organise by folders, parameterise them, drag and drop to your code window <kbd>Ctrl</kbd> + <kbd>Alt</kbd> + <kbd>T</kbd> to start or see here. – wBob Mar 8 '17 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.