set formatoptions+=c
I want to globally disable it. Is there an easy way to do
this? I know I can disable it for particular filetypes by
creating files in vimfiles\after\ftplugin\ specifying "set
formatoptions-=c" but there are a lot of them.
Two methods I've found from searching are
. Maintain a single file and use symbolic links to make vim
access it for each filetype. A bit clumsy - new filetypes
might appear later, I want to maintain real
filetype-specific files as well, etc.
. Use autocmd events to set this. This works in many cases
but different edge cases are missed by different events so
I'm not sure which events to use. Also it seems to be
"fighting vim" - trying to keep checking in case vim has
changed the setting and change it back. I'd like it to just
work, reliably.
Is there a simpler method?
regards,
Geoff
> > set formatoptions+=c
> > I want to globally disable it.
> Try adding this near the end of your vimrc:
> au VimEnter * au FileType * setlocal fo-=c
> This is supposed to add ":setlocal fo-=c" at the end of the list of
> FileType autocommands for any filetype. (The VimEnter event is triggered
> at the very end of startup.)
This is the solution I settled on. Gary's command also
worked for me but this one seems to cover more obscure
scenarios, and I like the idea of chaining two autocommands
together - neat.
What C Campbell suggested was something I orginally tried
and couldn't make work at all, because I didn't understand
how the after-directory works. I just created
~/vimfiles/after/_vimrc_afterwards as a file and it seemed
to ignore it. I didn't think of doing it as a plugin. I'll
bear that in mind as a general technique in future.
> The problem is that if you forget to break lines when typing a comment,
> you might find yourself with a single-line comment of, let's say, 1000
> characters, which might be, hm, shall we say, a little awkward?
Actually I don't use autowrapping at all, but I have
'textwidth' set so I can do 'gq' to wrap the text when
necessary.
It works for me because I don't need to print anything from
vim out (yet :)
> Another possible problem is that if you use the "filetype plugin off"
> command, it may disable this autocommand, which won't be set again by
> "filetype plugin on". In that case you should add it near the end of a
> ~/.vim/after/filetype.vim (for Unix / Linux / Mac OSX) or
> ~/vimfiles/after/filetype.vim (for Windows) (neither this file nor its
> directory exist by default, create them if necessary, DON'T modify
> $VIMRUNTIME/filetype.vim):
> "------------------------------------filetype.vim start
> augroup filetypedetect
> "
> " ... maybe some custom filetype-detection if-clauses
> "
> au FileType * setlocal fo-=c
> augroup END
> "------------------------------------filetype.vim end
> Thus will be set again every time you do ":filetype [plugin] [indent]
> on". I am less sure that this will remove the c flag *after* it has been
> set though.
It didn't remove the flag, I'm not sure why. I don't think
I ever turn it off anyway so it's not a problem in my case.
> Best regards,
> Tony.
> --
Thanks to everyone who suggested things. I've learnt quite
a bit about how the after-directory works and got a working
solution. Much appreciated.
regards,
Geoff