x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I change the indent rules inVisual Studio?

Hi,

How do you configured Visual Studio c++ indent for source code?

By default, it puts a tab indent after a macro like UPROPERTY() and in Epic code there are not indent.

I want to be as close as possible to Epic Formating.

Thanks,

Product Version: Not Selected
Tags:
more ▼

asked Apr 28 '14 at 09:31 PM in C++ Programming

avatar image

Elvince
494 43 70 157

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

Here are my C++ formatting rules. You'll need to change the extension back to .vssettings

My VS C++ Formatting Settings

Cheers, Nick

more ▼

answered Apr 28 '14 at 09:41 PM

avatar image

Nick Darnell ♦♦ STAFF
6k 77 37 151

avatar image Elvince Apr 29 '14 at 12:30 PM

Thanks for the file but this didn't solve my issue.

Anytime I set UPROPERTY() and press return to write the property defintion, it automatically indent it :(

Any other hints?

Thanks,

avatar image Nick Darnell ♦♦ STAFF Apr 29 '14 at 12:57 PM

Oh that - that's visual studio being visual studio. It attempts to do smart indenting but because C++ is a complicated language, it sometimes gets confused. The way to trick it - after you fix the extra indent with backspace or delete, use the arrow keys to leave the line instead of the mouse or the enter key, that will keep your manually chosen indention.

Cheers, Nick

avatar image Elvince Apr 29 '14 at 01:06 PM

Thanks for the tips... I hope this will get fix sometimes ^^

avatar image Elvince Apr 29 '14 at 01:08 PM

Thanks for the tips... I hope this will get fix sometimes ^^

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I wrote a visual studio extension to fix issues with smart indenting around UE4 macros. You can find it and instructions for installation on my github: https://github.com/hackalyze/ue4-vs-extensions

more ▼

answered Sep 15 '16 at 10:04 PM

avatar image

hackalyze
36 12 9

avatar image Brumsky Oct 11 '16 at 07:28 PM

Thank you! This is awesome!

avatar image Olathuss Jun 15 '19 at 10:25 PM

Perfect, thank you for this!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I was just struggling with this myself. I don't believe it's possible to make Visual Studio treat this case correctly. One option is to sidestep the problem on a case-by-case basis, as NickDarnell describes, but that can get really obnoxious.

Another option is just to turn off Visual Studio's auto-formatting entirely. This is unfortunate, because when it works it can be a very nice feature. However, Unreal's heavy use of macros and it's custom pre-processor can confuse the auto-formatter.

To turn it off, go to Tools -> Options... -> Text Editor -> C/C++ -> Formatting -> General, and then uncheck all of the checkboxes there.

Note that when you hit return after the UPROPERTY line, it will still give you the initial indentation. But it will no longer insist on re-inserting that indentation all the time.

more ▼

answered Jul 26 '14 at 10:25 PM

avatar image

Cifram
26 11 5

avatar image TTaM Dec 16 '15 at 08:39 PM

Personally, I just go mad on ctrl+z. It will undo any auto-formatting. Always does the trick.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

In Visual Studio Community 2013:

Go to Tools > Options > Text Editor > C/C++ > Tabs In the "Indenting" section select "Block" instead of Smart.

It will stop over-indenting after macros such as GENERATED_BODY(). However:

  • it will stop indenting after access specifiers such as "public:". You can still indent manually once and from there, the Block mode will keep your indentation.

  • it will stop indenting after other kinds of structure ending with () without {, such as if () with no {} to execute a single conditional instruction.

  • if you enter an opening bracket such as ( or { directly after the macro, or only after blank lines, the whole line will be over-indented at the same time. You can deactivate this behavior by unchecking "Automatically format braces when they are automatically completed" in Tools > Options > Text Editor > C/C++ > Formatting > General, but it will also stop useful behavior such as indenting after a {. Actually, the problem is that VS still consider what is after the macro as something that should be indented, i.e. any reformating operation will over-indent the next non-blank non-comment line after the macro. In practice, if you are listing your private attributes, you will probably have at least one field with no such symbol that will act as an inhibitor for the following lines. Attributes with list initializers and methods, however, will contain { / ( so be careful.

Alternative trick: add a semicolumn after the macro, and get some peace with that. Don't forget to remove it later, or you will have a compile error.

more ▼

answered Apr 15 '15 at 04:35 PM

avatar image

huulong
156 10 10

avatar image idbrii Nov 18 '15 at 10:35 PM

Using Block indenting instead of Smart for C++ didn't work for me on Visual Studio 2013. It still indented everything after GENERATED_BODY().

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question