How to automatically position the BETWEEN cursor in curly braces after entering a closing curly brace in C #?

Whenever I create a method signature in VS 2008 (C #), I print two curly braces:

public void Something () {}

This leaves the cursor to the right of the closing brace. Then I have to use the arrow keys to move the cursor between curly braces. Is there a better way to do this without using the arrow keys?

I expect it to place the cursor between curly braces when I type the final one so that I can start entering code.

+4
source share
5 answers

At the moment I do not have vs2008. Assuming that VS2008 still supports this, you can use code snippets. Chat below until you get what you need. (See Section "Code Snippet Manager")

<?xml version="1.0" encoding="utf-8" ?> <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"> <CodeSnippet Format="1.0.0"> <Header> <Title>b</Title> <Shortcut>b</Shortcut> <Description>Braces with cursor inside</Description> <Author>CrashCodes</Author> </Header> <Snippet> <Code Language="csharp"><![CDATA[{ $end$ }]]> </Code> </Snippet> </CodeSnippet> </CodeSnippets> 
+6
source

I believe Resharper is doing this. Not sure if there is a free option.

+2
source

Here is a macro to insert curly braces after the cursor and place the cursor on the line between them

  Sub InsertCurlyBraces() DTE.ActiveDocument.Selection.NewLine() DTE.ActiveDocument.Selection.Text = "{" DTE.ActiveDocument.Selection.NewLine(2) DTE.ActiveDocument.Selection.Text = "}" DTE.ActiveDocument.Selection.LineUp() End Sub 
+1
source

You can write a macro that inserts}, then moves the cursor, and then assigns the macro to the shift +] key combination, so your closing brace always runs your macro.

0
source

CodeRush does this as well.

0
source

All Articles