在 .vimrc 中,`set no兼容`完全没有用吗?
这个史诗般的问题中的几位用户将以下内容放入 .vimrc:
" Necesary for lots of cool vim things
set nocompatible
但这真的有必要吗?来自文档:
'compatible' 'cp'
boolean (default on, off when a |vimrc| or |gvimrc| file is found)
如果 set noknown
出现在 .vimrc
中,则意味着 .vimrc
文件存在,这看起来毫无意义。
Several users in this epic question put the following in the .vimrc
:
" Necesary for lots of cool vim things
set nocompatible
But is it really necessary? From the docs:
'compatible' 'cp'
boolean (default on, off when a |vimrc| or |gvimrc| file is found)
If set nocompatible
is going in a .vimrc
, that means that a .vimrc
file exists, seemingly making it pointless.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果是系统范围的 vimrc,则该选项不会关闭。因此,如果您要更改系统范围的 vimrc 并且需要它,则需要设置它。
从文档部分 *兼容默认* (强调我的):
另一个区别是,显式设置 'no兼容' 会否决使用 -C 标志 调用 vim。
是的,在任何其他情况下,在 vimrc 中设置“no兼容”都是无用的。
最后我认为这只是一个“安全胜于遗憾”的问题。
If it is the system-wide vimrc, this option won't be off. So, if you're changing the system-wide vimrc and you want it, you need to set it.
From the documentation section *compatible-default* (emphasis mine):
Another difference is that explicitly setting 'nocompatible' overrules calling vim with the -C flag.
In any other scenario, yes, setting 'nocompatible' in your vimrc is a noop.
In the end I think it's just a matter of "better safe than sorry".
许多人在 GitHub 上分享他们的 .vimrc 文件,我有时会测试设置而不替换我的 .vimrc 文件。 vim 允许我使用 -u 标志来做到这一点。
来自 vim ":help nocompromed"
这意味着,如果您与某人共享您的 .vimrc 并且他们使用 -u 标志来加载您的文件,则 vim 的配置将不会像该文件名为 .vimrc 并位于您的主目录中一样。
Many people share their .vimrc files on GitHub and I sometimes will test out settings without replacing my .vimrc file. vim allows me to do this with the -u flag.
From vim ":help nocompatible"
This means that if you share your .vimrc with someone and they use -u flag to load your file, vim won't be configured the same as if the file were named .vimrc and located in your home directory.
我在 Windows VM 上的 Cygwin 中使用 vim,每次处于插入模式时,按箭头键都会导致 vim 在屏幕上打印“A”、“B”、“C”或“D”,而不是滚动。我发现一个论坛说将 vim 置于不兼容模式可以修复它。值得庆幸的是,它做到了。
我在 ~/.vimrc 文件中放入“set no兼容”,问题仍然存在。所以也许它并不是100%无用。
I was using vim in Cygwin on a Windows VM and every time I was in Insert Mode, pressing arrow keys would result in vim printing "A", "B", "C" or "D" on the screen instead of scrolling. I found a forum that said putting vim in nocompatible mode would fix it. Thankfully, it did.
I put "set nocompatible" in my ~/.vimrc file and the problem remains gone. So perhaps it's not 100% useless.
根据约翰尼上面指出的,当我刚刚发现这一点时,我感到非常惊讶:
啊啊!!!
不,我没想到。
Debian(或 Debian Unstable,又名 Ubuntu)确实通过设置兼容覆盖默认设置,给用户带来了一场噩梦。
我希望您现在知道为什么当您来自 FreeBSD 时,您要做的第一件事就是通过将
set noknown
放入您自己的中来覆盖系统范围的设置~ /.vimrc
。因为否则你只会产生字母,而不是能够按照你习惯的方式移动光标。我认为这是一个可怕的想法。换句话说,在 Debian 和 Ubuntu 中,应该从系统范围的
vimrc.tiny
中删除这条set兼容
行,因为它会惹恼那些(还)不知道如何让光标键工作的新用户。正是这些东西迫使他们使用
nano
和其他东西,因为这些完全毫无意义的阻碍!我真的很想和曾经将这个更改传播到 Debian 系统范围资源文件的家伙谈谈。也许对于那些充分承认他的改变的人来说也是如此。
Johnny 是对的:在您的私人 PC 上,您可以从系统范围的 .vimrc(如果有)中删除上述行,并在 $HOME 上触摸一个空的 .vimrc。非常感谢您指出这一点,再次减少混乱。请注意,您必须拥有
~/.vimrc
(即使为空!),否则您将无法在不显式输入set no兼容的情况下使用游标
。Based on what Johnny pointed out above, I was simply astonished when I just found THIS out:
ARGH!!!
No I did NOT expect that.
Debian (or Debian Unstable aka Ubuntu) indeed DOES put up a nightmare to their users by overriding the default setting by set compatible.
I hope that you will now know why when you're coming from FreeBSD, the first thing you would have to do is override the system-wide setting by putting a
set nocompatible
into your own~/.vimrc
. Because otherwise you'd just produce letters instead of being able to move the cursor the way you've been used to.I think this is a horrid idea. In other words, this
set compatible
line ought to be removed from the system-widevimrc.tiny
in both Debian and Ubuntu, because it will annoy new users who are not (yet) as smart as knowing how to get the cursor keys working.It's things like these that force them to
nano
and others because of such entirely pointless blockers!I would really want to talk with the dude who once propagated this change to the system-wide resource file in Debian. And maybe also to the people who acknowledged his change to the fullest.
Johnny is right: on your private PC, you may remove said line from the system-wide .vimrc (if there), and touch an empty .vimrc on your $HOME. Thanks so much for pointing that out, way less clutter again. Note that you MUST have that
~/.vimrc
(even if empty!) as otherwise you will not be able to use the cursors without explicitly putting inset nocompatible
.使用
-u vimrc
选项时遇到了同样的问题,即使使用set noknown
也对我的一些旧设置表现不佳,经过一番搜索后,我发现了一个适合我的压缩版本:这可以避免在已设置不兼容标志时重新设置它。
vim
:help noknown
显示设置/重置选项值时的条件,滚动到该选项和值表,以供快速参考,影响此行为的条件是:got the same problem on using
-u vimrc
option, even doingset nocompatible
was misbehaving with some of my older setting, after some search i found one compactible version that works for me:this avoid re-setting of nocompatible flag when it is already set.
vim
:help nocompatible
shows conditions when it set/resets the options value, scroll to that table of options and values, for quick reference, conditions that effect this behaviour are: