I would like a textwidth of 80 by default in vim, but if specific filetypes have their own text width (in particular gitcommit where tw=72) I would like vim to honour that width.
In my .vimrc I have the line:
set tw=80
I have also tried
setlocal tw=80
However this seems to override the gitcommit width of 72.
If I remove the line then git commits work fine (wrap at 72) but a text file (for example) will not wrap automatically.
Is it possible to have vim wrap to 80 if nothing else is specified, but otherwise follow the specific filetype instructions?
As an aside, I think this used to work up until recently. I have tried removing everything else from my .virmrc but the set tw=80, but this doesn't make any difference.
EDIT: If I open up a git commit message editor, and run
:verbose set tw?
vim displays:
textwidth=80
Last set from ~/.vimrc
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
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: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: