If you need to toggle between using Tabs or spaces in your Visual Studio projects and files, you can use this simple Macro from within VS to toggle between tabs vs. no tabs:
- Open the Macro Editor via Tools -> Macros -> Macros IDE (Alt+F11)
- Paste in the following VBA code:
1 Public Sub ToggleTabs()
2 Dim currentSetting As Boolean = DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value
3 DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value = Not currentSetting
4 End Sub
- Open the Macro Editor via Tools -> Macros -> Macro Explorer (Alt+F8)
- Run the “ToggleTabs” macro
For more information on other settings that can be utilized via macros, see the MSDN page
Or, see how one can use Settings files to achieve the same goal, but I think the Macro is a little easier / faster to switch between them.
EDIT: Here is a more complete script that I use that will toggle the tabs of C#, SQL, HTML, and javascript, but only when you are editing a file of that language’s:
1 Public Sub ToggleTabs()
2 If DTE.ActiveDocument.Language = "CSharp" Then
3 Dim currentSetting As Boolean = DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value
4 DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value = Not currentSetting
5 End If
6
7 If DTE.ActiveDocument.Language = "SQL" Then
8 Dim currentSQLSetting As Boolean = DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value
9 DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value = Not currentSQLSetting
10 End If
11
12 If DTE.ActiveDocument.Language = "HTML" Then
13 Dim currentHTMLSetting As Boolean = DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value
14 DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value = Not currentHTMLSetting
15 End If
16
17 If DTE.ActiveDocument.Language = "JScript" Then
18 Dim currentJScriptSetting As Boolean = DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value
19 DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value = Not currentJScriptSetting
20 End If
21
22 End Sub