gpt4 book ai didi

vim - 在 Vim 中重新格式化,明智的方式

转载 作者:行者123 更新时间:2023-12-05 00:00:00 24 4
gpt4 key购买 nike

除了普通的 gq,我不经常重新格式化文本所以这可能很简单,但似乎没有运气在帮助中找到它。

无论如何,我有这样的文字

Funnily enough, that was exciting. 
"I've just about had enough of this," said a voice beside him.
He looked up. A girl had come down the other path. Her face was red with exertion under the pale make-up, her hair hung over her eyes in ridiculous ringlets, and she wore a dress which, while clearly made for her size, was designed for someone who was ten years younger and keen on lace edging.
She was quite attractive, although this fact was not immediately apparent.
"And you know what they say when you complain?" she demanded. This was not really addressed to Victor. He was just a convenient pair of ears.

这在 Vim 中阅读起来很痛苦。所以我尝试用 gq 重新格式化它这给了我这个
Funnily enough, that was exciting.  "I've just about had enough of this,"
said a voice beside him. He looked up. A girl had come down the other path.
Her face was red with exertion under the pale make-up, her hair hung over
her eyes in ridiculous ringlets, and she wore a dress which, while clearly
made for her size, was designed for someone who was ten years younger and
keen on lace edging. She was quite attractive, although this fact was not
immediately apparent. "And you know what they say when you complain?" she
demanded. This was not really addressed to Victor. He was just a convenient
pair of ears.

这是相当无用的,因为在这种情况下原始行结尾具有特殊含义。我想要完成的是这个
Funnily enough, that was exciting. 
"I've just about had enough of this," said a voice beside him.
He looked up. A girl had come down the other path. Her face was red with
exertion under the pale make-up, her hair hung over her eyes in ridiculous
ringlets, and she wore a dress which, while clearly made for her size, was
designed for someone who was ten years younger and keen on lace edging.
She was quite attractive, although this fact was not immediately apparent.
"And you know what they say when you complain?" she demanded. This was not
really addressed to Victor. He was just a convenient pair of ears.

即保留原始行结尾,但将比 textwidth 长的每一行“分成”几行。因此它符合预定义的列宽限制。

有人对如何做到这一点有任何想法吗?这是一个相当大的文件,我需要某种方式来处理它。

最佳答案

视觉上选择所有行,然后在 ex 模式下执行:

:norm gqq

gqq 重新格式化一行。 :norm with a range 对范围内的每个 in 单独应用正常代码。这意味着您申请 gqq单独在每一行上。因为您的 textwidth设置为特定长度(例如 80 ),这意味着不会连接/换行较短的行。

我已经在您的示例文本上对此进行了测试,它只是提供了您想要的。

顺便说一句,你可以使用vim的 :formatprg使用外部程序对其进行修改。这可以更好地控制您要使用外部应用程序修改的内容。欲了解更多信息,请阅读 :h formatprg

关于vim - 在 Vim 中重新格式化,明智的方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10953777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com