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.
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
.
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.
Download "Comment Reflower" from http://www.kynosarges.de/CommentReflower.html, unzip into the directory C:\Program Files (x86)\Visual Studio Comment Reflower
.
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.
In VS2012, select Tools..Options..AddIn Security
and add the path C:\Program Files (x86)\Visual Studio Comment Reflower
.
Restart VS2012.
Now there is new menu items: Tools..Reflow Comment at Cursor
and Tools..Comment Reflower Settings
.
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
.
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.
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
.
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:
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!):
If you are using ReSharper, there is the free Agent Smith plugin that can reflow comments.
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#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With