Vim formatoptions-=or
If you found that the flag o
is being inserted back in formatoptions
after startup, you should find out why this is happening and fix it. This seems cleaner than always executing an autocmd
, even after the option is removed.
You could check where the option is set issuing with following commands:
:5verbose set fo?
:5verbose setl fo?
Edit:
If your problem is with a ftplugin
file that lies on Vim directory ($VIMRUNTIME/ftplugin
) you shouldn't change that file, because that change would be undone when Vim is updated. The proper way to change it is in your after
directory, as explained in :h after-directory
.
Supposing that the problem occurs with c
filetype, create file ~/.vim/after/ftplugin/c.vim
containing your setlocal formatoptions-=
commands.
@mm2703 's solution didn't work for me, especially for java files, but this change did. I also wrapped it in an augroup
, statement so resourcing .vimrc
won't re-register the autocmd
:
augroup Format-Options
autocmd!
autocmd BufEnter * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" This can be done as well instead of the previous line, for setting formatoptions as you choose:
autocmd BufEnter * setlocal formatoptions=crqn2l1j
augroup END
If your 'formatoptions'
contains options in different order, like ro
, then -=or
won't work. Try
set formatoptions-=o
set formatoptions-=r
From help remove-option-flags
:
Note that you should add or remove one flag at a time. If 'guioptions' has the value "ab", using "set guioptions-=ba" won't work, because the string "ba" doesn't appear.