Solved

Visual Studio 2013 auto-formatting is messing with my comments

Posted on 2013-11-02
14
2,889 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +1
14 Comments
 
LVL 29

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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
 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

617 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