使用 vim 重排注释块
我正在清理别人的代码并使用 vim。我想重排评论,以便它们的格式保持一致。
例如:
# one two three four five six seven
# eight nine
# ten eleven twelve thirteen fourteen
# fifteen sixteen seventeen
# eighteen
# nineteen
会变成:
# one two three four five six seven eight nine ten eleven
# twelve thirteen fourteen fifteen sixteen seventeen
# eighteen nineteen
因此,一个工作流程可以轻松取消代码注释,重排段落,然后重新注释代码并保留缩进。如果有一个现有的插件可以做到这一点,那就太好了。
I'm cleaning up someone else's code and working with vim. I'd like to reflow the comments so that they're formatted consistently.
For example:
# one two three four five six seven
# eight nine
# ten eleven twelve thirteen fourteen
# fifteen sixteen seventeen
# eighteen
# nineteen
Would become:
# one two three four five six seven eight nine ten eleven
# twelve thirteen fourteen fifteen sixteen seventeen
# eighteen nineteen
So, a workflow that would easily uncomment the code, reflow the paragraph and then re-comment the code with the indentation preserved. If there is an existing plugin which does exactly this, that would be great.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gq 命令考虑注释和缩进。我通常使用 V 直观地选择行(使用 k 和 j),然后按 g q。
textwidth
选项用于将行格式化为适当的长度。请参阅:help gq
了解更多信息。The
gq
command takes comments and indentation into account. I normally use V to visually select the lines (with k and j) and then press gq. Thetextwidth
option is used to format the lines at the appropriate length. See:help gq
for more information.有一个内置的命令文本重排:
所以当你有这个:
它变成这样:
它也会将长行分成较小的行。
There is a built-in command text reflow:
So when you have this:
It becomes this:
It will also break long lines into smaller ones.