visual-studio Visual Studio 代码片段 Cursor
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2100227/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio code snippets Cursor
提问by Stormenet
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.
现在我想告诉 Visual Studio 之后光标应该去哪里。我在网上搜索过,实际上对这可能实现的希望不大。
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
});
回答by Henrik S?derlund
Use the $end$ variable as shown in the following "if" snippet for c#.
使用 $end$ 变量,如以下 c# 的“if”代码段所示。
<?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>

