vim文本宽度重新格式化

dea*_*ost 9 vim text-width

我想重新格式化我的文件,因此在最大线宽为79.我没有:set tw=79gggqG,结果不出我所料.当一条线小于79 col时,它下面一行的字符向上移动,超过79 col的行不会分成两行.

编辑:嗯,我被误认为除了带星号的行外,它的断线超过了79.

--CONVENTIONS**************************************************************************************
Run Code Online (Sandbox Code Playgroud)

此外,当行<79时,它仍会移动字符.

Bir*_*rei 9

一种可能的解决方案,尽管不是最好的方案.

取消定义formatexpr并让外部fold程序将文本格式设置为79个字符宽度.

:set formatexpr=
:set formatprg=fold\ -w\ 79
Run Code Online (Sandbox Code Playgroud)

现在:

gg              # Go to beginning of file.
gq              # Format until...
G               # End of file.
Run Code Online (Sandbox Code Playgroud)

最后删除那些回车(^ M):

:%s/\r//g
Run Code Online (Sandbox Code Playgroud)

在我的测试中它改变了一些重音字符,其他一些行被修改了,但是自己尝试一下.否则,您可以编写自己的格式函数并将其与formatexpr选项一起使用.