11

我可以发誓我见过人们输入函数标题,然后点击一些组合键来自动创建函数括号并在它们之间插入光标,如下所示:

void foo()_

void foo()
{
    _
}

这是内置功能吗?

4

5 回答 5

6

这些工具看起来不错(尤其是 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

编辑:我用宏记录器来做这个,还不错

于 2008-08-13T05:30:37.527 回答
5

查看Resharper - 它是具有此功能的 Visual Studio 插件,以及许多其他开发帮助。

另请参阅C# Completer,另一个附加组件。

如果您想自己动手,请查看这篇文章。疯狂的是,一个人应该这样做,虽然。

于 2008-08-13T05:20:34.147 回答
2

它可以通过使用代码片段来实现,有些已经内置(尝试输入“svm”并点击 TAB-TAB)..

网上有很多关于创建这些的信息:

杰夫在这里自己发了一个帖子

有一个谷歌!我经常使用它们!:D

于 2008-08-13T05:14:51.693 回答
2

看看视觉辅助

于 2008-08-13T05:15:22.283 回答
0

我刚刚根据上面的@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
于 2012-09-05T15:47:09.540 回答