我发誓我已经看到人们键入函数头然后点击一些键组合来自动创建函数括号并将光标插入它们之间,如下所示:
void foo()_
至
void foo()
{
_
}
这是内置功能吗?
我发誓我已经看到人们键入函数头然后点击一些键组合来自动创建函数括号并将光标插入它们之间,如下所示:
void foo()_
至
void foo()
{
_
}
这是内置功能吗?
查看 ReSharper的 - 它是一个具有此功能的Visual Studio插件,以及许多其他开发帮助。
另见 C#完成者,另一个附加组件。
如果您想自己动手,请查看 本文。但是,一个人应该这样做是疯了。
这些工具看起来很不错(特别是Resharper,但价格在200-350美元!)但我最后只是记录了一个宏并将其分配给ctrl + alt + [
Macro出来是这样的:
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
编辑:我使用宏录制器来制作它并没有太糟糕
看一眼 视觉辅助 同样。
我刚刚在@ 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