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.
If you are using ReSharper, there is the free Agent Smith plugin that can reflow comments.
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 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 want near perfect comment justification with a single keystroke, use Comment Reflower.
Works with
VS2012
,VS2013
andVS2015
.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.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 thatVersion
increments from10.0
to11.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 pathC:\Program Files (x86)\Visual Studio Comment Reflower
.Restart VS2012.
Now there is new menu items:
Tools..Reflow Comment at Cursor
andTools..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
to12.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
Go to
Tools..Options..Keyboard
, typereflow
inShow commands containing
, selectCommentReflower.Connect.ReflowPoint
, type a key combination (e.g.Ctrl-J
) in the boxPress shortcut keys
, then hitAssign
.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 theTools
menu:Update margin width
Go into
Tools..Comment Reflower Settings
and change theWrap Width
from the default of 80 to something wider, such as140
, and the "Minimum Block Width" to10
(do*not*
set it to anything smaller!):