1

Found a solution: snippet shortcuts cannot have underscores in them, or they will... well, they just won't expand from intellisense.

I am on Visual Studio 2022

Snippets / Intellisense are otherwise working fine, if I start typing "for", I get the right suggestions, and if I select one and press tab, it expands fine.

I have created my first custom code snippet (just to remind me to flush stdin after using scanf_s). It has no bells or whistles, it's just to insert some text. It does not share a name with any other command, variable, snippet or anything in Intellisense (the name is just "myscanf_s"). I am trying it in an open .cpp file, which matches its declared language.

It works in two ways, and fails in just one:

A) I can choose "Snippet - Insert Snippet", find it under "My Code Snippets", and insert it just fine.

B) It shows up as a suggestion when I type.

C) But, when selecting it as a suggestion and pressing tab (or double-pressing tab, double-clicking, or ctrl-spacing), it just inserts the full shortcut name.

Why is my custom snippet working so differently?

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>myscanf_s</Title>
            <Description>Basic help for scanf_s</Description>
            <Shortcut>myscanf_s</Shortcut>
        </Header>
        <Snippet>
            <Code Language="CPP">
                <![CDATA[
                //%d is 'Dec. int', %u is 'Unsigned dec. int.', %s is 'String, %e is 'float', %c is 'single Char'
                scanf_s("TYPE_SPECIFIER", &VARIABLE, WIDTH_OF_INPUT);
                getchar();
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>```

0 Answers0