Reputation: 43467
i have my formatoptions
set like this in my ~/.vimrc
:
set formatoptions=caq1njw
Sometimes I run a script which lets me edit a temporary plain-text file which has paths that begin with //
(They are perforce file paths).
This causes vim to apply wrapping comment paragraph rules so if I have a few short file paths that add up to less than textwidth
characters long, it will merge the file paths while I edit this file list! This would be super extra bad.
Now I know how to get Vim to apply different settings upon opening different filetypes by using the .vim/after/ftplugin
. For instance if I wanted formatoptions
to be something specific for javascript files I would edit some ftplugin/javascript.vim
file, as evidenced by this:
:verbose set formatoptions
formatoptions=a1njwcroql
Last set from ~/bin/share/vim/vim73/ftplugin/javascript.vim
Press ENTER or type command to continue
(my vim is installed under ~/bin
, yeah, this is unconventional)
So it looks like the bundled javascript.vim is applying l
and r
in addition to my .vimrc
's caq1njw
. That's fine, I can configure vim's behavior for javascript however I want.
But what I want is for plain, normal, undetected filetype files to NOT use caq1njw
. And, for all other recognized filetypes to use caq1njw
.
Is there a way to do this without adding set formatoptions=caq1njw
to each and every filetype that I use?
Basically some sort of ftplugin/vanilla.vim
that is run only when the filetype is undetected.
Upvotes: 2
Views: 382
Reputation: 172668
In case that temporary plain-text file follows any (path and/or filename) pattern, I'd define an autocmd on that:
:autocmd BufNew,BufRead /tmp/tempfile*.tmp setlocal formatoptions=...
For the general case, it's difficult to trigger on the FileType
event not being thrown. You'd have to use another event that comes after that, e.g.:
:autocmd BufWinEnter * if empty(&l:filetype) | setlocal formatoptions=... | endif
I'd go with the first alternative, though.
Upvotes: 1