代码之家  ›  专栏  ›  技术社区  ›  Daniel Vandersluis

禁用所有文件类型的自动注释

  •  3
  • Daniel Vandersluis  · 技术社区  · 14 年前

    我打开了 filetype plugin 对于我添加的一些railsvim插件,但它的一个副作用似乎是现在所有文件类型中都启用了自动注释(例如,如果我用 # ,下一行 输入 在插入模式或 等进入插入模式,也会得到一个 #

    我找到一个 guide 禁用自动注释 formatoptions ,并将以下内容添加到my.vimrc中:

    au FileType * setlocal formatoptions-=cro
    

    然而,我仍然遇到问题——除非我明确 :source .vimrc ,(或输入 setlocal ...

    然后我找到了一个 second guide 其中谈到了在ftplugin脚本运行后使用after-ftplugin脚本进行更改,但是他们的解决方案是为~/.vim/after/ftplugin中的每个文件类型创建指向中心文件的符号链接,这对我来说似乎是一个难题。

    有没有办法创建一个通用的after-ftplugin脚本或者我处理这个问题的方法不对?任何帮助都将不胜感激。

    6 回复  |  直到 14 年前
        1
  •  5
  •   Curt Nelson    14 年前

    “after”插件怎么样?在中创建文件 ~/.vim/after/plugin/ 打电话 noAutoComments.vim (或者别的什么)把你的自动驾驶仪放进去?

    编辑:

    这样做的原因是什么?我只是在猜测,但我有种感觉 autocmd ~/.vimrc 文件正在被其他文件删除(但在“after”文件被源化之前)。

    最后我把我的手机拿走了 ~/.vim ~/.vimrc公司 使用以下3行:

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

    ~/.vimrc公司 ~/.vim/ 目录 自动抄表 似乎按预期工作(Vim 7.1)。

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

    我还没有确定什么文件(插件)是造成这个问题,但是。

        2
  •  4
  •   Daniel Vandersluis    14 年前

    我做了更多的调查,我的位置 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
    

    结果 :详细设置fo? 是:

    formatoptions=ql
      Last set from ~/.vimrc
    

    ... 这是期望的结果。所以看起来 需要在启用文件类型插件后指定。

        3
  •  3
  •   studog    13 年前

    :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
    

    因为我碰到过这个。

        4
  •  1
  •   DrAl    14 年前

    autocmd

    :verbose set formatoptions?
    

    这将告诉您该选项的设置位置,从而更容易确定要使用哪个autocmd。或者,如果你不介意一些小的黑客攻击,我可能会这样做只是找出它在插件中的位置,并注释掉那一行(并记下它,以防你升级插件)。你也可以联系插件的作者,让他们把它变成一个可配置的选项。

    自动抄表 事件,请阅读:

    :help {event}
    
        5
  •  1
  •   qed    12 年前

        # vim without auto comment
        alias vi="vi +'set fo-=cro'"
    
        6
  •  1
  •   milarepa    11 年前

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

    我想关键是 autocmd filetype plugin on .