In Visual Studio 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 });
You can also press ctrl + shift + I . In mac os it is control.
To create or edit your own snippets, select User Snippets under File > Preferences (Code > Preferences on macOS), and then select the language (by language identifier) for which the snippets should appear, or the New Global Snippets file option if they should appear for all languages.
VS Code supports multiple cursors for fast simultaneous edits. You can add secondary cursors (rendered thinner) with Alt+Click. Each cursor operates independently based on the context it sits in. A common way to add more cursors is with Shift+Alt+Down or Shift+Alt+Up that insert cursors below or above.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With