Awesome Visual Studio Macros [closed]

2020-01-27 09:12发布

For a small community discussion, what are some essential Visual Studio macros you use?

I just started learning about them, and want to hear what some of you can't live without.

14条回答
做自己的国王
2楼-- · 2020-01-27 10:03

I'm currently working on two different projects with different coding standards, one that uses tabs for line beginnings and another that uses spaces. This macro will toggle between which standard is used based on which environment is currently active:

Public Sub ToggleTabs()
  If DTE.ActiveDocument.Language = "CSharp" Then
      Dim currentSetting As Boolean = DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value
      DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value = Not currentSetting
  End If

  If DTE.ActiveDocument.Language = "SQL" Then
      Dim currentSQLSetting As Boolean = DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value
      DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value = Not currentSQLSetting
  End If

  If DTE.ActiveDocument.Language = "HTML" Then
      Dim currentHTMLSetting As Boolean = DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value
      DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value = Not currentHTMLSetting
  End If

  If DTE.ActiveDocument.Language = "JScript" Then
      Dim currentJScriptSetting As Boolean = DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value
      DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value = Not currentJScriptSetting
  End If

End Sub
查看更多
闹够了就滚
3楼-- · 2020-01-27 10:04

I mapped ctrl-shift-G to a macro that generates a GUID in registry format - this is useful for editing IDL

查看更多
登录 后发表回答