Visual Studio 的评论重花
是否有内置命令或工具可以在 Visual Studio 中重排 C# 注释?
有时,一段代码需要多行注释,经过大量编辑后,您必须在适当的位置手动插入换行符,以免它超出编辑器窗口的右边缘。我希望能够通过一个键命令来完成此操作。
使用 Visual Studio 多年后,我仍然怀念 emacs 中 Mq(c-fill-paragraph)的功能。
编辑:Agent Smith 插件不会回流方法主体中的注释。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当我还是一名 Visual C++ 开发人员时,我编写了一个相当可配置的注释格式化工具,称为 Comment Reflower。此后我更换了平台,因此停止了移植,但幸运的是 Christoph Nahr 在 http://www 上保持了它的活力.kynosarges.de/CommentReflower.html
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
如果您想通过一次按键获得近乎完美的评论合理性,请使用评论重花。
适用于
VS2012
、VS2013
和VS2015
。VS2012:安装/升级 Visual Studio 2012 的 Comment Reflower
更新 2015-08-31:现在有一个 Comment Reflower 扩展可在扩展库中找到,可以直接从
Tools > 轻松安装。 VS2012、VS2013 和 VS2015 中的扩展和更新
。从http://www.kynosarges.de/CommentReflower.html,解压到目录
C:\Program Files (x86)\Visual Studio Comment Reflower
。更新文件
CommentReflower.Addin
,使Version
从10.0
递增到11.0
(这会将其从 VS2010 升级)到 VS2012)。注意:此 .xml 文件中有两个点,您必须在其中更新此版本。在 VS2012 中,选择
Tools..Options..AddIn Security
并添加路径C:\Program Files (x86)\Visual Studio Comment Reflower
。重新启动VS2012。
现在有新的菜单项:
Tools..Reflow Comment at Cursor
和Tools..Comment Reflower Settings
。VS2013:安装/升级 Visual Studio 2013 的 Comment Reflower
更新 2015-08-31:现在扩展库中提供了 Comment Reflower 扩展,可以直接从
Tools > 轻松安装。 VS2012、VS2013 和 VS2015 中的扩展和更新
。重复上述说明,并将步骤 2 中的版本从
11.0
更改为12.0
。VS2015:安装/升级 Visual Studio 2015 的 Comment Reflower
现在有一个 Comment Reflower 扩展直接从
Tools > 轻松安装的扩展库VS2012、VS2013 和 VS2015 中的扩展和更新
。感谢@Martin Liversage 指出了这一点。
要添加一个快捷键来调整光标所在的当前注释
转到
工具..选项..键盘
,在显示命令中键入
,选择reflow
,其中包含CommentReflower.Connect.ReflowPoint
,在按快捷键
框中键入组合键(例如Ctrl-J
),然后点击分配
。现在,如果您将光标放在评论上,然后按所述组合键 (
Ctrl-J
),它会自动(并且精美地)为您证明该评论的合理性。您应该会看到绑定键出现在Tools
菜单中:更新边距宽度
进入
Tools..Comment Reflower Settings
并将Wrap Width
从默认值 80 更改为更宽的值,例如140
,并且“最小块宽度”为10
(*不要*
将其设置为更小的值!):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!):如果您使用 ReSharper,可以使用免费的 Agent Smith 插件来回流评论。
If you are using ReSharper, there is the free Agent Smith plugin that can reflow comments.
如果您使用
//
或///
样式注释 CodeMaid 对我来说非常有用。它是免费且开源的,我可以在 C++ 和 C# 中使用它。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#.