我可以发誓我见过人们输入函数标题,然后点击一些组合键来自动创建函数括号并在它们之间插入光标,如下所示:
void foo()_
到
void foo()
{
_
}
这是内置功能吗?
我可以发誓我见过人们输入函数标题,然后点击一些组合键来自动创建函数括号并在它们之间插入光标,如下所示:
void foo()_
到
void foo()
{
_
}
这是内置功能吗?
这些工具看起来不错(尤其是 Resharper,但价格为 200-350 美元!)但我最终只是录制了一个宏并将其分配给 ctrl+alt+[
宏是这样出来的:
Sub FunctionBraces()
DTE.ActiveDocument.Selection.NewLine
DTE.ActiveDocument.Selection.Text = "{}"
DTE.ActiveDocument.Selection.CharLeft
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.LineUp
DTE.ActiveDocument.Selection.Indent
End Sub
编辑:我用宏记录器来做这个,还不错
查看Resharper - 它是具有此功能的 Visual Studio 插件,以及许多其他开发帮助。
另请参阅C# Completer,另一个附加组件。
如果您想自己动手,请查看这篇文章。疯狂的是,一个人应该这样做,虽然。
看看视觉辅助。
我刚刚根据上面的@Luke 创建了一个。这个,你想按 Enter 然后按你的组合键,它会插入:
if ()
{
}
else
{
}
它会将您的光标放在 if 语句的括号中。
Sub IfStatement()
DTE.ActiveDocument.Selection.Text = "if ()"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "else"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "{"
DTE.ActiveDocument.Selection.NewLine(2)
DTE.ActiveDocument.Selection.Text = "}"
DTE.ActiveDocument.Selection.LineUp(False, 7)
DTE.ActiveDocument.Selection.EndOfLine()
DTE.ActiveDocument.Selection.CharLeft(3)
End Sub