如何在编辑期间修复 vim textwidth?

And*_*ter 4 vim text-editors word-wrap

当编辑我在 .vimrc 中限制为 tw=80 的文件时,当我稍后回来编辑它们时,行长度最终会到处都是。例如

lets say for the sake of argument that this line hits 80 characters
there and continues on the next line as normal
Run Code Online (Sandbox Code Playgroud)

编辑后...

lets say for the sake of argument (edit edit edit edit) that this 
line hits 80 characters
there and continues on the next line as normal
Run Code Online (Sandbox Code Playgroud)

代替

lets say for the sake of argument (edit edit edit edit) that this 
line hits 80 characters there and continues on the next line as 
normal
Run Code Online (Sandbox Code Playgroud)

任何人都知道我可以做些什么来解决这种行为?

Hep*_*ite 5

您可以使用 " gq" 正常模式命令来重新格式化文本。它适用于视觉选择或动作。例如,您可以使用文本对象“ ap”(可用于代替动作),表示“段落”(光标所在的当前段落):

gqap
Run Code Online (Sandbox Code Playgroud)

或者,您可以直观地选择要重新格式化的段落,然后键入“ gq”。

另一个技巧是在 'formatoptions' 选项中添加 "a" 和可选的 "w":

:set formatoptions+=aw
Run Code Online (Sandbox Code Playgroud)

这将在您键入时自动重新格式化段落,而无需求助于“ gq”。

看:

:help gq
:help auto-format
:help 'formatoptions'
:help motion.txt
Run Code Online (Sandbox Code Playgroud)