Solved

Visual Studio 2013 auto-formatting is messing with my comments

Posted on 2013-11-02
14
2,608 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
Comment Utility
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
Comment Utility
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
Comment Utility
Are you using tabs in the above diagram or are these spaces only?
0
 
LVL 40

Author Comment

by:evilrix
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 86

Expert Comment

by:jkr
Comment Utility
0
 
LVL 40

Author Comment

by:evilrix
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> *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
Comment Utility
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
Comment Utility
No solution available. For me, this is the simplest workaround.

Thanks guys, for trying.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

743 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

18 Experts available now in Live!

Get 1:1 Help Now