Search code examples
c#visual-studiointellisensecode-snippets

Visual Studio cw snippet works, but then doesn't when I do it again


I type 'cw' press tab twice and bam 'Console.WriteLine()' appears. I then press enter and move to another line type 'cw' press tab twice and wtf 'cw.WriteLine()' appears.

enter image description here

I tried throwing my computer out the window but remembered that I need it.


Solution

  • First, please check whether the version of your VS2022 is the latest version, I am currently using VS community 17.4.4, and the code snippets shortcut 'cw' works fine on my side.

    1, So first, please make sure you are based on the latest version of VS2022:

    enter image description here

    2, Second, you can try to reset the environment settings and turn off synchronized settings on a particular computer(If you don't encountered the issue when you don't login in please unselect the setting.)

    Reset environment settings:

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    turn off synchronized settings on a particular computer:

    enter image description here]7

    enter image description here

    3, And please check whether other snippets have this problem, if not, I suggest you to create your own code snippets, import it and then try again.

    Creat a file named xxx.snippet:

    <?xml version="1.0" encoding="utf-8" ?>
    <CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>xxx</Title>
                <Shortcut>xxx</Shortcut>
                <Description>Code snippet for Console.WriteLine</Description>
                <Author>Microsoft Corporation</Author>
                <SnippetTypes>
                    <SnippetType>Expansion</SnippetType>
                </SnippetTypes>
            </Header>
            <Snippet>
                <Declarations>
                    <Literal Editable="false">
                        <ID>SystemConsole</ID>
                        <Function>SimpleTypeName(global::System.Console)</Function>
                    </Literal>
                </Declarations>
                <Code Language="csharp"><![CDATA[$SystemConsole$.WriteLine($end$);]]>
                </Code>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    

    After that, import this code snippets:

    enter image description here

    enter image description here

    After that, write xxx and double press Tab.