Disabling autorun for all file types

I have included filetype pluginrails vim for some plugins that I added, but a side effect of this is that now auto-comment is turned on in all types of files (for example, if I start a line with #, the next line, either Enterin insert mode, or Oetc., to enter insert mode, also get #).

I found a guide to turn off automatic commenting formatoptionsand added the following to my .vimrc:

au FileType * setlocal formatoptions-=cro

However, I still run into problems - unless I explicitly :source .vimrc(or type setlocal ...directly), it does not take effect. I decided that it was because vim ftplugins override my options with their own.

Then I found a second guide that talks about using a post-ftplugin script to make changes after running ftplugin scripts, however their solution is to create symbolic links for each file in ~ / .vim / after / ftplugin in the central file, and that seems to me cloned.

Is there a way to create a generic script after ftplugin or am I approaching this issue incorrectly? Any help would be appreciated.

+3
source share
6 answers

What about the after plugin? Create a file in ~/.vim/after/plugin/called noAutoComments.vim(or something else) and put your autocmd in it?

Edit:

? , , autocmd ~/.vimrc - ( "" ).

~/.vim ~/.vimrc 3 :

filetype plugin on
syntax on
au FileType * setlocal formatoptions-=cro

~/.vimrc no ~/.vim/ autocmd (Vim 7.1).

, :

:verbose set formatoptions?
formatoptions=ql
      Last set from ~/.vimrc

, () .

+5

, , autocmd .vimrc , formatoptions vim ftplugins . vim --noplugin, , :

vimrc :

au FileType * setl fo-=cro
filetype plugin indent on

:verbose set fo? :

formatoptions=croql
  Last set from /usr/share/vim/vim72/ftplugin/ruby.vim

, vimrc :

filetype plugin indent on
au FileType * setl fo-=cro

:verbose set fo? :

formatoptions=ql
  Last set from ~/.vimrc

..., . , , autocmd .

+3

, ...

:he :set-=:

            When the option is a list of flags, {value} must be
            exactly as they appear in the option.  Remove flags
            one by one to avoid problems.

    " Turn off auto-commenting
    au FileType * setlocal formatoptions-=c
    au FileType * setlocal formatoptions-=r
    au FileType * setlocal formatoptions-=o

.

+3

autocmd , , :

:verbose set formatoptions?

, ​​, , autocmd . , , , , , , , , ( , - ). .

autocmd :

:help {event}
+1

I tried the solutions suggested by many, but none of them worked for me, but I found one very simple solution, namely in ~ ~ .bash_aliases:

    # vim without auto comment
    alias vi="vi +'set fo-=cro'"
+1
source

I struggled with this problem, and finally I worked with the following lines:

syntax on
filetype on
filetype plugin on
au FileType * setlocal formatoptions-=cro

I think the key here is what autocmdis after filetype plugin on.

+1
source

Source: https://habr.com/ru/post/1754465/


All Articles