Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio, per solution indentation settings

I'm working on a couple of different things and some use tabs, some use 2 spaces for indents, another users 4 spaces for indents etc.

The option to set this in Visual Studio is in Tools->Options->Text Editor-><language>->Tabs

Is there some way to override these settings on a per solution bases?

like image 884
Fire Lancer Avatar asked Jul 31 '09 11:07

Fire Lancer


People also ask

How do I turn on auto indent in Visual Studio?

Auto formatting settings in Visual Studio Show activity on this post. Select the text you want to automatically indent. Click menu Edit → Advanced → *Format Selection, or press Ctrl + K , Ctrl + F . Format Selection applies the smart indenting rules for the language in which you are programming to the selected text.


2 Answers

UPDATE: VS 2017 supports EditorConfig natively: https://blogs.msdn.microsoft.com/dotnet/2016/12/15/code-style-configuration-in-the-vs2017-rc-update/

In VS 2010 and above, there's an extension that sets the indentation based on .editorconfig file in the solution/project root:

http://visualstudiogallery.msdn.microsoft.com/c8bccfe2-650c-4b42-bc5c-845e21f96328

There's also similar extension for Visual Studio Code.

like image 82
Tereza Tomcova Avatar answered Sep 20 '22 20:09

Tereza Tomcova


Here is one (admittedly hacky) way to achieve what you are looking for:

1) create a macro that changes the indentation (source)

 Sub Set-Indent(indent As integer)      Dim props As EnvDTE.Properties = DTE.Properties("TextEditor", "C/C++")      Dim ts As EnvDTE.Property = props.Item("TabSize")      Dim ins As EnvDTE.Property = props.Item("IndentSize")      ts.Value = indent       ins.Value = indent   End Sub 

2) Hook that up with your solution loading: In the macro explorer, choose EnvironmentEvents, select SolutionEvents in the first drop-down, Opened in the second. You now have a macro that will trigger every time you open a solution. You just need to map your solutions to the required indentation.

like image 35
Bahbar Avatar answered Sep 21 '22 20:09

Bahbar