Visual Studio 2013 auto-formatting is messing with my comments

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.
LVL 40
evilrixSenior Software Engineer (Avast)Asked:
Who is Participating?
 
evilrixConnect With a Mentor Senior Software Engineer (Avast)Author Commented:
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
 
peprCommented:
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
 
evilrixSenior Software Engineer (Avast)Author Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jkrCommented:
Are you using tabs in the above diagram or are these spaces only?
0
 
evilrixSenior Software Engineer (Avast)Author Commented:
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
 
jkrCommented:
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
 
evilrixSenior Software Engineer (Avast)Author Commented:
>> completely turn off auto-formatting
I've tried that and none of the options seem to disable it! :(

#sonotimpressedmicrosoft
0
 
jkrCommented:
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
 
jkrCommented:
0
 
evilrixSenior Software Engineer (Avast)Author Commented:
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
 
phoffricCommented:
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
 
phoffricCommented:
>> *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
 
evilrixSenior Software Engineer (Avast)Author Commented:
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
 
evilrixSenior Software Engineer (Avast)Author Commented:
No solution available. For me, this is the simplest workaround.

Thanks guys, for trying.
0
All Courses

From novice to tech pro — start learning today.