2

I have the following in my vimrc file:

:set formatoptions-=cro

However, when I load the vimrc from scratch (i.e., open a new terminal session and start vim with it), it seems to be overwritten somewhere:

enter image description here

If I again set it with that same command it 'corrects' it to the right value, but I'm wondering why this is occurring in the first place (do plugins tend to overwrite this?) or if I should put this option somewhere other than in my vimrc file so it doesn't get overwritten.

2

Reading :h 'formatoptions' reveals that it's "local to buffer". This means that every buffer has a value of formatoptions of its own. Setting it in "vimrc" can only provide a default value.

But the problem is that the defaults may be overwritten by standard ftplugin (:h ftplugin, :h :filetype etc.) which provides "better" values based on filetype. To see if it's the case you do:

:verbose set formatoptions?
    formatoptions=xyz
        Last time set in /path/to/ftplugin/vim.vim line 42

if I should put this option somewhere other than in my vimrc file so it doesn't get overwritten

In fact, you should put it the way your options overwrite system values.

~/.vim/after/ftplugin/vim.vim

setlocal formatoptions=xyz
1

Use :verbose like:

:verbose set formatoptions?

See :h :verbose, :h :verbose-cmd and :h 'verbose'.

When I execute this while editing a C file I get:

  formatoptions=croql
        Last set from ~/.vim/after/ftplugin/c/c.vim line 41
0

Another way to set the formatoptions is with an autocommad, which overrules ftplugin.

augroup NoAutoComment
  au!
  au FileType * setlocal formatoptions-=cro
augroup end

You can spefify filetypes by replacing the * (e.g: c,sh)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.