set textwidth in vim without overriding filetype specific

青春壹個敷衍的年華 提交于 2019-12-05 18:18:13

Vim has this covered with the global vs. buffer-local options. As you describe, you're supposed to :set a global default in your ~/.vimrc, and some filetypes may override the global default with :setlocal.

For troubleshooting, try

:verbose set tw?

This should tell you the last place that modified the option value.

Edit

For ft=gitcommit, it has special logic to only set the textwidth if (the global value) is empty:

if &textwidth == 0
    " make sure that log messages play nice with git-log on standard terminals
    setlocal textwidth=72
    let b:undo_ftplugin .= "|setl tw<"
endif

Your global settings prevents this from taking effect. The solution is to unconditionally set the textwidth yourself: In ~/.vim/after/ftplugin/gitcommit.vim, put this:

    setlocal textwidth=72
    let b:undo_ftplugin .= "|setl tw<"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!