Visual Studio代码段游标 [英] Visual Studio code snippets Cursor

查看:83
本文介绍了Visual Studio代码段游标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio中,当您插入一个代码段并完成文字插入时,光标会跳到该代码段的开头.

In Visual Studio when you insert a snippet and finish inserting literals the cursor jumps to the beginning of the snippet.

现在,我想告诉Visual Studio光标随后应移至何处.我已经在网上搜索了,实际上对此抱有希望.

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>

然后插入:

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

推荐答案

使用$ end $变量,如以下用于c#的"if"代码段所示.

Use the $end$ variable as shown in the following "if" snippet for c#.

<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets  xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <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>

这篇关于Visual Studio代码段游标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆