This feels like a dumb question, but I can\'t find an answer on the Internet (or in VIM help). I\'m using VIM 7.2 on Mac OS X. All I want to do is wrap my lines at 72 characters
I was looking for an answer to the same question and had to scramble around a bit before I found the solution in the VIM docs. So, i thought i will update the thread and save others the time.
The problem in my case was that the default ftplugin was disabling textwidth.
Just updating your .vimrc with (:set tw=79 && :set formatoptions+=t
) won't work since the fplugins are sourced after vimrc.
Here are the steps that i followed:
1) find out what your current formatoptions (inside vim)
:set formatoptions?
formatoptions=croql (note no 't')
2) create a filetype.vim file as suggested by vimdocs (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) add the line :set formatoptions+=t
&& :set textwidth=79
in that file.
Voila! next time when you open the file it will set the textwidth to your desired characters.
As a debugging aid you can always check which file is overriding your vimrc setting by prepending your command with verbose. So for e.g. if i want to check who updated the formatoptions last, i would type
:verbose set formatoptions?
formatoptions=croqlt
Last set from ~/.vim/after/ftplugin/fortan.vim