views:

329

answers:

1

In visual studio (2008) when you insert a snippet and finish inserting literals the cursor jumps to the beginning of the snippet.

Now I'd like to tell visual studio where the cursor should go afterwards. I've searched the web and actually hold little hope for this to be possible.

To illustrate, suppose I have this snippet:

<Code Language="csharp" Kind="method body" Delimiter="$"><![CDATA[this.SyncThreadRunInvoke(() =>
            {

            });]]>
    </Code>

Then after inserting:

this.SyncThreadRunInvoke(() =>
            {
            []<- I want the cursor here
            });
+2  A: 

This is what the "if" snippet for c# looks like, maybe you can get something useful from that.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt;
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>if</Title>
            <Shortcut>if</Shortcut>
            <Description>Code snippet for if statement</Description>
            <Author>Microsoft Corporation</Author>
            <SnippetTypes>
                <SnippetType>Expansion</SnippetType>
                <SnippetType>SurroundsWith</SnippetType>
            </SnippetTypes>
        </Header>
        <Snippet>
            <Declarations>
                <Literal>
                    <ID>expression</ID>
                    <ToolTip>Expression to evaluate</ToolTip>
                    <Default>true</Default>
                </Literal>
            </Declarations>
            <Code Language="csharp"><![CDATA[if ($expression$)
    {
        $selected$ $end$
    }]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
Henrik Söderlund
I'm guessing that maybe the $end$ thingy may be what you are looking for.
Henrik Söderlund
Yep, I've tried it now, it is definately $end$ that you want. One little caveat though: If you are creating a snippet that surrounds existing code with new code, such as curly braces or whatever, it seems logical to me that the following would place the cursor *after* the surrounded code:$selection$ $end$ But it does not. It places the cursor immediately *before* the surrounded code.
Henrik Söderlund
Yep, that did the trick. And I'm not surrounding code, so that's no issue for me. Thanks!
Stormenet