禁用所有文件类型的自动注释
我为我添加的一些rails vim插件打开了文件类型插件
,但这样做的副作用似乎是现在所有文件类型都启用了自动注释(例如,如果我以#
,下一行,无论是在插入模式下按 Enter 或 O 等进入插入模式,也会得到一个 #< /代码>)。
我找到了指南来禁用自动评论formatoptions
,并将以下内容添加到我的 .vimrc 中:
au FileType * setlocal formatoptions-=cro
但是,我仍然遇到问题 - 除非我明确 :source .vimrc
,(或输入 setlocal .. .
直接),它没有生效。我确定是这种情况,因为 vim 的 ftplugins 用它们自己的选项覆盖了我的选项。
然后我找到了 第二个指南,其中讨论了使用 after ftplugin 脚本在 ftplugin 脚本之后进行更改已经运行,但是他们的解决方案是为 ~/.vim/after/ftplugin 中的每个文件类型创建到中心文件的符号链接,这对我来说似乎很混乱。
有没有办法创建通用的 after-ftplugin 脚本,或者我是否错误地处理了这个问题?任何帮助将不胜感激。
I turned on filetype plugin
for some rails vim plugins I added, but a side effect of this seems to be that now autocommenting has been enabled in all filetypes (for instance, if I start a line with #
, the next line, either by Enter in insert mode or O, etc. to enter insert mode, will also get a #
).
I found a guide to disabling the auto-commenting formatoptions
, and added the following to my .vimrc:
au FileType * setlocal formatoptions-=cro
However, I am still running into problems -- unless I explicitly :source .vimrc
, (or enter the setlocal ...
directly), it is not taking effect. I determined that this is the case because vim's ftplugins are overriding my options with their own.
I then found a second guide which talks about using an after ftplugin script to make changes after the ftplugin scripts have run, however their solution is to create symlinks for every single filetype in ~/.vim/after/ftplugin to a central file, and this seems to be kludgy to me.
Is there any way to create a generic after-ftplugin script or am I approaching this problem incorrectly? Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
“之后”插件怎么样?在
~/.vim/after/plugin/
中创建一个名为noAutoComments.vim
(或其他名称)的文件并将你的 autocmd 放入其中?编辑:
这有效的原因是什么?我只是在这里猜测,但我有一种感觉
~/.vimrc
文件中的autocmd
被其他一些文件删除(但在“after”之前)文件正在获取)。我最终删除了我的
~/.vim
目录,并用以下 3 行替换了我的~/.vimrc
:在我的
~/.vimrc 中只有这些行
并且没有~/.vim/
目录,autocmd
似乎按预期工作(Vim 7.1)。对于我编辑的任何文件:
但是,我尚未确定哪个文件(插件)导致了此问题。
How about an "after" plugin? Create a file in
~/.vim/after/plugin/
callednoAutoComments.vim
(or whatever) and place your autocmd in that?Edit:
The reason this works? I'm only guessing here, but I have a feeling that the
autocmd
in the~/.vimrc
file is getting removed by some other file (but before the "after" files are getting sourced).I ended up removing my
~/.vim
directory and replaced my~/.vimrc
with the following 3 lines:With only these lines in my
~/.vimrc
and no~/.vim/
directory, theautocmd
seems to work as expected (Vim 7.1).For any file that I edit:
I have yet to determine what file (plugin) is causing this issue however.
我做了更多调查,似乎 .vimrc 文件中
autocmd
的位置决定了formatoptions
是否会被 vim 的 ftplugins 覆盖。使用vim --noplugin
禁用所有外部插件,我发现以下结果:如果我的 vimrc 看起来像:
:verbose set fo?
的结果是:但是,如果我的 vimrc 中的行是相反的:
:verbose set fo?
的结果是:... 这是所需的结果。所以看来启用文件类型插件后需要指定
autocmd
。I've done some more investigation and it seems that the location of my
autocmd
within my .vimrc file determines ifformatoptions
will be overridden by vim's ftplugins or not. Usingvim --noplugin
to disable all external plugins, I found the following results:If my vimrc looks like:
The result of
:verbose set fo?
is:However, if the lines in my vimrc are reversed:
The result of
:verbose set fo?
is:... which is the desired result. So it seems that the
autocmd
needs to be specified after filetype plugins are enabled.这可能不会生效的另一个原因...
来自
:he :set-=
:我有,
因为我遇到过这个。
Another reason this might not be taking effect...
From
:he :set-=
:I have
because I've run into this.
如果您找到正确的一个,使用各种
autocmd
事件之一来设置配置选项应该可以工作,但我首先运行:这将告诉您设置该选项的位置,这可能会使其生效更容易确定要使用哪个 autocmd。或者,如果您不介意一些轻微的黑客行为,我可能会做的方式就是找出它在插件中的设置位置并注释掉该行(并记下它,以防您升级插件)。您还可以联系该插件的作者并要求他们将其设为可配置选项。
对于可用的
autocmd
事件,请阅读以下内容:Using one of the various
autocmd
events to set the configuration option should work if you find the right one, but I'd start by running:This will tell you where the option was set, which may make it easier to determine which autocmd to use. Alternatively, if you don't mind a bit of minor hacking, the way I'd probably do it is just to find out where it's set in the plugin and comment out that line (and make a note of it in case you ever upgrade the plugin). You could also contact the plugin's author and ask them to make it a configurable option.
For the available
autocmd
events, read this:我尝试过许多人提出的解决方案,但没有一个对我有用,但我发现了一个非常简单的解决方法,即在您的 ~/.bash_aliases 中:
I have tried solutions proposed by many, but none of them worked for me, but I found one very simple workaround, namely, in your ~/.bash_aliases:
我一直在努力解决这个问题,最后我使用了以下几行:
我认为这里的关键是
autocmd
位于filetype 插件
之后。I was struggling with this issue and I finally works with the following lines:
I think the key here is that the
autocmd
is place after thefiletype plugin on
.