是否有相当于 Linux/Unix “fold” 的 Vim? 命令?

发布于 2024-07-13 15:12:00 字数 273 浏览 1 评论 0原文

我意识到 Vim 中有一种隐藏/折叠行的方法,但我正在寻找一种选择文本块并让 Vim 在第 80 列或附近换行的方法。

大多数情况下我想在注释中使用它我在现有评论中添加了一些文本,使其超过 80 个字符。 如果它也可以在换行时在行首插入注释标记,那就太好了。 另外,我更喜欢不自动换行整个文件的解决方案,因为在将结构化代码保持在 80 个字符行长度以下时,我使用了一个特定的约定。

这主要针对 Python 代码,但我也有兴趣学习该问题的一般解决方案,以防我必须将其应用于其他类型的文本。

I realize there's a way in Vim to hide/fold lines, but what I'm looking for is a way to select a block of text and have Vim wrap lines at or near column 80.

Mostly I want to use this on comments in situations where I'm adding some text to an existing comment that pushes it over 80 characters. It would also be nice if it could insert the comment marker at the beginning of the line when it wraps too. Also I'd prefer the solution to not autowrap the entire file since I have a particular convention that I use when it comes to keeping my structured code under the 80 character line-length.

This is mostly for Python code, but I'm also interested in learning the general solution to the problem in case I have to apply it to other types of text.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

撑一把青伞 2024-07-20 15:12:00
gq

它由 textwidth 选项控制,请参阅 ":help gq" 了解更多信息。

默认情况下,gq 将在当前行上工作,但您可以使用 Ctrl+V 突出显示可视块,并设置多行/段落的格式。

gqap 执行文本的当前“段落”。

gq

It's controlled by the textwidth option, see ":help gq" for more info.

gq will work on the current line by default, but you can highlight a visual block with Ctrl+V and format multiple lines / paragraphs like that.

gqap does the current "paragraph" of text.

我的黑色迷你裙 2024-07-20 15:12:00

看一下“:help =”和“:help 'equalprg”

:set equalprg=fold

,在正常模式下==通过外部折叠程序过滤当前行。 或者视觉选择某些内容并点击=

Take a look at ":help =" and ":help 'equalprg"

:set equalprg=fold

and in normal mode == filters the current line through the external fold program. Or visual-select something and hit =

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