我正在寻找关于同样问题的答案,在找到VIM文档中的解决方案之前必须进行一些周折。因此,我想更新此线程并节省其他人的时间。
在我的情况下,问题是默认的ftplugin禁用了textwidth。
仅更新您的.vimrc(
:set tw = 79 &&:set formatoptions + = t
)不起作用,因为vimrc之后会源泉fplugins。
以下是我遵循的步骤:
1)找出您当前的formatoptions(在vim内部)
:set formatoptions?
formatoptions=croql (note no 't')
2) 根据vimdocs建议创建一个filetype.vim文件 (http://vimdoc.sourceforge.net/htmldoc/filetype.html#ftplugin-overrule)
Overrule the settings after loading the global plugin.
You must create a new filetype plugin in a directory from the end of
'runtimepath'. For Unix, for example, you could use this file:
vim ~/.vim/after/ftplugin/fortran.vim
In this file you can change just those settings that you want to change.
3) 在该文件中添加以下行::set formatoptions+=t
&& :set textwidth=79
。
完成!下次打开文件时,它将把文本宽度设置为您想要的字符数。
作为调试辅助工具,您可以始终检查哪个文件覆盖了您的vimrc设置,方法是在命令前加上verbose。例如,如果我想检查最后更新formatoptions的人是谁,我会键入:
:verbose set formatoptions?
formatoptions=croqlt
Last set from ~/.vim/after/ftplugin/fortan.vim