Solved

Visual Studio 2013 auto-formatting is messing with my comments

Posted on 2013-11-02
14
2,657 Views
Last Modified: 2013-11-08
Let's say I add the following comment into some code, which documents the expected layout of a binary search tree:

   /*
             8
            / \
           3   9
          / \
         1   6
            / \
           4   7
   */

Open in new window


As some point, later, I use CTRL-A, CTRL-K, CTRL-F to reformat the code. It seems that Visual Studio is taking it upon itself to also reformat my comment. The up-shot is that my correctly formatted comment is messed up and ends up looking something like this:

   /*
             8
             / \
             3   9
             / \
             1   6
             / \
             4   7
             */

Open in new window


Clearly, this is not what I want and - IMHO - this behaviour is just plain wrong (and stupid). The question is, how on earth do I turn it off? I've tried every option to do with formatting C/C++ in the Text Editor settings and I've drawn a blank.

I'm not interested in suggestions for other editors/IDEs, I am only interested in knowing how to disable this "feature", specifically, in VS2013 for C/C++ (preferably before my laptop is thrown out of the window).

Thank you.
0
Comment
Question by:evilrix
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 28

Expert Comment

by:pepr
ID: 39619778
I can only confirm the problem. I was not able to find anything related to auto formatting of comments.

I agree this is not what one wants. Your pseutographics is the extreme; however, I often format "normal text" into indented items, etc. -- think about the markdown formatting rules.
0
 
LVL 40

Author Comment

by:evilrix
ID: 39619804
I often document things in code like this. When working with complex data structures (this is just a simple example, of course) a picture is worth a thousand words. I consider this to be a significant defect in Visual Studio and, yet one more reason why I would normally avoid using it like the plague. Unfortunately, my current project necessitates the use of VS (I would normally be quite happy using ViM and the command line).
0
 
LVL 86

Expert Comment

by:jkr
ID: 39619976
Are you using tabs in the above diagram or are these spaces only?
0
 
LVL 40

Author Comment

by:evilrix
ID: 39620040
Given that these are comments - and so are not subject to the syntax or semantics of the language (other than those required to make them comments) I would hope that it shouldn't matter. However, it's a valid question to ask... the're spaces. I never use tabs - tabs are evil in source code :)

I guess the point is that VS absolutely should not be messing with my comments - they are not it's to play with. Comments are there for documentation and it should not be an unreasonable expectation to be able to lay this out however I so choose.

Sorry, I had to get that rant off my chest :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 39620099
Hm, if it isn't tabs, I am clueless. I guess the only advice I could give then would be to completely turn off auto-formatting...
0
 
LVL 40

Author Comment

by:evilrix
ID: 39620124
>> completely turn off auto-formatting
I've tried that and none of the options seem to disable it! :(

#sonotimpressedmicrosoft
0
 
LVL 86

Expert Comment

by:jkr
ID: 39620191
Don't have VS2013 here, but up to VS2012, I'd go to "Tools|Options|Text Editor|C/C++|Formatting" and set evrything to "false". For VS2013 however, here's the mandantory SO link: http://stackoverflow.com/questions/18298072/how-do-i-turn-off-auto-formatting-in-vs2013-for-c (via MSDN search *duck*)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 86

Expert Comment

by:jkr
ID: 39620199
0
 
LVL 40

Author Comment

by:evilrix
ID: 39620201
Ok, I'll take a look. I'm using the full RTW version so with a bit of luck I am just overlooking something (that should be obvious, but clearly is not!).

*come back ViM, all is forgiven =/
0
 
LVL 40

Accepted Solution

by:
evilrix earned 0 total points
ID: 39620208
It seems I can stop it screwing with my comments if I put a fix position non-white-space character in from of everything. In other words, it seems the auto-format is trying to line up all the text so that it all starts on the same column. *sigh*

   /*
    *         8
    *        / \
    *      (3)   9
    *      / \
    *   [1]   6
    *        / \
    *       4   [7]
    */

Open in new window


Unless someone can tell me how to stop it doing this I propose to accept this as the solution (workaround).
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39620532
From above links, I gather that what you experience is not by design, but an actual MS VS 2013 bug, so this bad behavior should be fixed someday. To avoid having to manually add those *'s to prevent the undesired formatting, you can use their comment/uncomment utility. Starting with your OP:
   /*
             8
            / \
           3   9
          / \
         1   6
            / \
           4   7
   */

Open in new window

highlight your comment including your comment delimiters. Then select Ctrl/E + C (or Edit->Advanced->Comment Select) and you get this mess:
   ///*
   //          8
   //         / \
   //        3   9
   //       / \
   //      1   6
   //         / \
   //        4   7
   //*/

Open in new window

You can uncomment with Ctrl/E + U.
0
 
LVL 32

Expert Comment

by:phoffric
ID: 39620821
>> *come back ViM, all is forgiven =/
I read that you can get ViM binary for Windows, or if you prefer, I thought I saw a source code download to build the ViM executable for Windows. Then when you edit a file and save it, VS 2013 should detect the change and ask you if you want to sync it to your Windows editor.

Or, it also looks like you can integrate ViM into VS 2012 (so maybe 2013 as well). This link provides a clue as to how to go about doing this:
VsVim brings the power of vim to Visual Studio
0
 
LVL 40

Author Comment

by:evilrix
ID: 39620845
Yes, I know. I already use it. It is just a shim for the VS functionality and doesn't help solve this problem. Of course, real ViM behaves correctly.
0
 
LVL 40

Author Closing Comment

by:evilrix
ID: 39632978
No solution available. For me, this is the simplest workaround.

Thanks guys, for trying.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What are the big features of MVC5? 4 74
Eclipse Neon and jdk 1.8.0 11 138
C++ :Change value from  DisableCMD registry 4 51
Installshield for Embarcadero EX 10.1 Berlin 4 20
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now