使用 vim 重排注释块

发布于 2024-12-20 09:35:58 字数 499 浏览 4 评论 0原文

我正在清理别人的代码并使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

季末如歌 2024-12-27 09:35:58

gq 命令考虑注释和缩进。我通常使用 V 直观地选择行(使用 kj),然后按 g qtextwidth 选项用于将行格式化为适当的长度。请参阅 :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. The textwidth option is used to format the lines at the appropriate length. See :help gq for more information.

┾廆蒐ゝ 2024-12-27 09:35:58

有一个内置的命令文本重排:

gwip - reflow paragraph

所以当你有这个:

# 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

它也会将长行分成较小的行。

There is a built-in command text reflow:

gwip - reflow paragraph

So when you have this:

# one two three four five six seven
# eight nine
# ten eleven twelve thirteen fourteen
# fifteen sixteen seventeen 
# eighteen
# nineteen

It becomes this:

# one two three four five six seven eight nine ten eleven twelve thirteen
# fourteen fifteen sixteen seventeen eighteen nineteen

It will also break long lines into smaller ones.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文