Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: any one click switch between tabs and spaces indentation?

I'm member of several different teams and (of course ;) some teams prefers tabs over spaces and vice versa.

Is there any more user friendly solution then loading user profile via menu->Tools... which is 10 clicks long?

I looked at devenv.exe command line parameters if there is any for loading particular user profile to have two separate *.lnk launchers of Visual Studio, but there isn't such parameter.

Then I tried to record macro, but VS is able to record only the Tools.ImportandExportSettings command and cannot record all the steps of the following wizard.

Thx for suggestions, Petr

like image 225
Petr Felzmann Avatar asked Nov 28 '10 20:11

Petr Felzmann


People also ask

How do you use spaces instead of tabs in VS Code?

Go to File ➤ Preferences ➤ Settings or just press Ctrl + , In the Search settings bar on top insert editor. insertSpaces. You will see something like this: Editor: Insert Spaces and it will be probably checked.


1 Answers

There is a macro in this blog entry by James Alexander to quickly toggle between tabs and spaces within Visual Studio. Then just add a toolbar command that maps to the macro and you have your one click solution.

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
like image 168
Scott Lerch Avatar answered Sep 23 '22 15:09

Scott Lerch