Question

Is there a built-in command or tool that can reflow C# comments in Visual Studio?

Sometimes, a section of code requires several lines of comments, and after extensive editing you have to manually insert the line breaks in the appropriately places so that it does not flow past the right edge of your editor window. I'd like to be able to do this with a single key command.

After many years of using Visual Studio I still miss the ability to M-q (c-fill-paragraph) in emacs.

Edit: The Agent Smith plugin does not reflow comments in the method body.

Was it helpful?

Solution

If you are using ReSharper, there is the free Agent Smith plugin that can reflow comments.

OTHER TIPS

Back when I was a Visual C++ Developer I wrote a fairly configurable comment formatting tool called Comment Reflower. I have since changed platforms and so stopped doing ports, but thankfully Christoph Nahr has kept it alive at http://www.kynosarges.de/CommentReflower.html

If you want near perfect comment justification with a single keystroke, use Comment Reflower.

Works with VS2012, VS2013 and VS2015.

VS2012: To install/upgrade Comment Reflower for Visual Studio 2012

Update 2015-08-31:There is now a Comment Reflower extension available in the extension gallery that easily installs directly from Tools > Extensions and Updates in VS2012, VS2013 and VS2015.

  1. Download "Comment Reflower" from http://www.kynosarges.de/CommentReflower.html, unzip into the directory C:\Program Files (x86)\Visual Studio Comment Reflower.

  2. Update file CommentReflower.Addin so that Version increments from 10.0 to 11.0 (this upgrades it from VS2010 to VS2012). NOTE: There are two spots in this .xml file where you have to update this version.

  3. In VS2012, select Tools..Options..AddIn Security and add the path C:\Program Files (x86)\Visual Studio Comment Reflower.

  4. Restart VS2012.

  5. Now there is new menu items: Tools..Reflow Comment at Cursor and Tools..Comment Reflower Settings.

VS2013: To install/upgrade Comment Reflower for Visual Studio 2013

Update 2015-08-31:There is now a Comment Reflower extension available in the extension gallery that easily installs directly from Tools > Extensions and Updates in VS2012, VS2013 and VS2015.

Repeat instructions above, and change the version in step 2 from 11.0 to 12.0.

VS2015: To install/upgrade Comment Reflower for Visual Studio 2015

There is now a Comment Reflower extension available in the extension gallery that easily installs directly from Tools > Extensions and Updates in VS2012, VS2013 and VS2015.

Thanks to @Martin Liversage for pointing this out.

To add a shortcut key that justifies the current comment your cursor is on

  1. Go to Tools..Options..Keyboard, type reflow in Show commands containing, select CommentReflower.Connect.ReflowPoint, type a key combination (e.g. Ctrl-J) in the box Press shortcut keys, then hit Assign.

  2. Now, if you position your cursor on a comment, and press said key combination (Ctrl-J), it will automatically (and beautifully) justify the comment for you. You should see the bound key appear in the Tools menu:

enter image description here

Update margin width

Go into Tools..Comment Reflower Settings and change the Wrap Width from the default of 80 to something wider, such as 140, and the "Minimum Block Width" to 10 (do *not* set it to anything smaller!):

enter image description here

If you use // or ///-style comments CodeMaid has worked great for me. It is free and open source, and I can use it in both C++ and C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top