Prevent Visual Studio from indenting code after multi-line template - visual-studio

I have recently discovered that Visual Studio likes to indent things after a template which takes up multiple lines, as you can see here:
After the template, in which I like to list parameters on different lines to prevent one huge line, the class declaration is indented by a tab. It indents the whole class declaration, so possibly hundreds of lines end up indented unnecessarily.
This happens every time I use Visual Studio's auto formatting tool, which is rather annoying, as I do want to be able to use auto format (it's very helpful), but just not this specific "feature"(?). I've looked through all the options in Tools -> Options -> Text Editor -> C/C++ -> Formatting, but I have not managed to find one that fixes this issue.
How can I prevent Visual Studio from indenting code after multi-line templates like this?

Related

Visual Studio -> wrap every parameter

Using Visual Studio 2019, I found a really useful refactoring option in 'Quick actions and refactoring':
(might come from PowerTools, whatever)
I just wondered how:
I can make this wrapping settings a default formatting settings
Or apply this formatting on my whole solution at once (without resharper)
For the later, a solution with Visual Studio Code would be perfect as well !
Thanks for your help
You can try using Rewrap extension which formats code, comments, and other text to a given line length (80 by default).
The main Rewrap command is: Rewrap Code / Comment, by default bound to
Alt+Q. Put the text cursor inside a comment line, block or plain text
paragraph and invoke the command to wrap. You can also select just a few lines, or multiple comments in one selection.
There is currently an Open request for this in the VS Code Issue tracker on GitHub

Visual Studio 2015 won't auto-indent lines correctly in All Languages

I'm using Visual Studio 2015 (14.0.x - update 3) and no matter what I try, I can't get All Languages to do Smart indenting. I go into Tools -> Options -> Text Editor -> All Languages -> Tabs and set it like so:
I've got a handler file open in VS (.ashx file) with inline code:
Notice that when I position my cursor right after the opening curly brace and hit Enter, the cursor goes to the next line, but indents too far over. This does not happen when a c# file is being edited. When I go back into Options to see what is going on, I am surprised to find Smart formatting cleared:
It doesn't matter how many times I re-select Smart, it doesn't honor it, and it clears it again. I don't believe ASHX file types have their own registered Text Editor type in VS, but maybe it does, listed under something unexpected, and that is overwriting it. I can't see any types that even resemble 'handler', or etc.
I even tried hand-editing the .vssettings file to enable Smart, but it still doesn't work, and Smart is cleared again when I go into Options.
I have read this post and tried to follow it, but my case is a little different.
How can I get the same indent behavior on my ASHX file as I get with .cs files, so that when hitting Enter after a line, it goes to the correct place on the next line, as expected?
Smart indenting is not applicable for all languages and hence the check is disappeared for All Languages, but the option is checked for C# ,html etc. for any applicable language.
Please refer to this link: https://learn.microsoft.com/en-us/visualstudio/ide/reference/options-text-editor-all-languages-tabs?view=vs-2015

How to prevent Visual Studio 2015 reformatting on uncommenting a block

If I comment out a block of code using the comment comment (Ctrl+E,C) and then uncomment (Ctrl+E,U) then the code is reformatted based on whatever options are set for things like braces in new lines, spacing around brackets, etc.
Is there any way to disable this behaviour and just leave the code as it was?
I don't recall seeing this behaviour prior to Visual Studio 2015.
OK I just found the relevant setting:
Tools -> Options -> Text Editor -> Basic -> Advanced -> Pretty listing (reformatting) of code

Visual Studio 2013 auto indent

In Visual Studio 2013, under Tools > Options > Text Editor > File Extension, I have set three file extensions, namely .cginc, .compute, and .shader (these are Unity3D shader files) to use Microsoft Visual C++ for auto formatting.
Sometimes auto indent (for curly braces) works, and sometimes it doesn't...I can't find any rhyme or reason for this. When it doesn't work, it starts every new line flush to the left.
I Google around every couple weeks and can't find an answer.
Does anyone know any setting to make auto indent work consistently?
Try this:
Tools -> Options -> Select the language of your choice (Expand the menu) -> Select Formatting (Expand this sub menu) -> Select Indendation
Once you have selected Indentation, on the right are options displayed - Check/Tick the option: Indent Braces.
Note: You may also format the entire document/file using the shortcut Ctrl+K+D

Visual Studio Macro to Indent C/C++ Braces

We have an old project that we maintain that uses brace indenting. Rather than having to change my Visual Studio options every time I switch projects, I'd like to be able to do this quickly and easily.
I'm trying to write a macro in Visual Studio to turn Brace Indenting on and off.
The checkbox is under Text Editor -> C/C++ -> Formatting
Indentation: Indent Braces
This doesn't work:
DTE.Properties("TextEditor", "C/C++").Item("IndentBraces").Value = True
I get "Value does not fall within the expected range."
Any ideas? I haven't been able to find anything on this.
I found the following is the correct macro code to make this work
DTE.Properties("TextEditor", "C/C++ Specific").Item("IndentBraces").Value = True
see: "Determining Names of Property Items in Tools Options Pages" which is only mildly helpful in this situation but gave me enough of a clue to find it.

Resources