在 Visual Studio 中,当您插入代码片段并完成插入文字时,光标会跳转到代码片段的开头。
现在我想告诉 Visual Studio 之后光标应该去哪里。我在网上搜索过,实际上对此不太抱有希望。
为了说明这一点,假设我有这个片段:
<Code Language="csharp" Kind="method body" Delimiter="$"><![CDATA[this.SyncThreadRunInvoke(() =>
{
});]]>
</Code>
插入后:
this.SyncThreadRunInvoke(() =>
{
[]<- I want the cursor here
});
最佳答案
使用 $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>
关于visual-studio - Visual Studio 代码片段光标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2100227/