在 .vimrc 中,`set no兼容`完全没有用吗?

发布于 2024-11-04 00:45:34 字数 462 浏览 0 评论 0原文

这个史诗般的问题中的几位用户将以下内容放入 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

茶花眉 2024-11-11 00:45:34

如果是系统范围的 vimrc,则该选项不会关闭。因此,如果您要更改系统范围的 vimrc 并且需要它,则需要设置它。

从文档部分 *兼容默认* (强调我的):

当 Vim 启动时,'兼容'
选项已打开。这将在以下情况下使用
Vim 开始初始化。但
一旦找到用户 vimrc 文件,
或当前目录中的 vimrc 文件
目录,或“VIMINIT”
设置了环境变量,就会
设置为“不兼容”。

另一个区别是,显式设置 '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):

When Vim starts, the 'compatible'
option is on. This will be used when
Vim starts its initializations. But
as soon as a user vimrc file is found,
or a vimrc file in the current
directory
, or the "VIMINIT"
environment variable is set, it will
be set to 'nocompatible'.

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".

橘寄 2024-11-11 00:45:34

许多人在 GitHub 上分享他们的 .vimrc 文件,我有时会测试设置而不替换我的 .vimrc 文件。 vim 允许我使用 -u 标志来做到这一点。

vim -u test_vimrc

来自 vim ":help nocompromed"

(注意:系统范围的 vimrc 或 gvimrc 文件不会发生这种情况,
也不适用于使用 |-u| 给出的文件论证)。

这意味着,如果您与某人共享您的 .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.

vim -u test_vimrc

From vim ":help nocompatible"

(Note: This doesn't happen for the system-wide vimrc or gvimrc file,
nor for a file given with the |-u| argument).

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.

懷念過去 2024-11-11 00:45:34

我在 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.

网名女生简单气质 2024-11-11 00:45:34

根据约翰尼上面指出的,当我刚刚发现这一点时,我感到非常惊讶:

$ cat /usr/share/vim/vimrc.tiny
" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after

set compatible

啊啊!!!

不,我没想到。
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:

$ cat /usr/share/vim/vimrc.tiny
" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after

set compatible

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-wide vimrc.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 in set nocompatible.

爱本泡沫多脆弱 2024-11-11 00:45:34

使用 -u vimrc 选项时遇到了同样的问题,即使使用 set noknown 也对我的一些旧设置表现不佳,经过一番搜索后,我发现了一个适合我的压缩版本:

" Avoid side-effects when nocompatible has already been set.
if &compatible
  set nocompatible
endif

这可以避免在已设置不兼容标志时重新设置它。

vim :help noknown 显示设置/重置选项值时的条件,滚动到该选项和值表,以供快速参考,影响此行为的条件是:

  1. 当“兼容”为“兼容”时,选项设置为 {set value} 中给定的值
    设置。
  2. 当设置了“兼容”时,选项设置为 {set value} 中给定的值,并且当设置“兼容”时,选项设置为其 Vim 默认值
    未设置。
  3. 设置“兼容”时选项不会更改,但在取消设置“兼容”时设置为其 Vim 默认值。

got the same problem on using -u vimrc option, even doing set nocompatible was misbehaving with some of my older setting, after some search i found one compactible version that works for me:

" Avoid side-effects when nocompatible has already been set.
if &compatible
  set nocompatible
endif

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:

  1. Option is set to the value given in {set value} when 'compatible' is
    set.
  2. Option is set to the value given in {set value} when 'compatible' is set AND is set to its Vim default value when 'compatible' is
    unset.
  3. Option is NOT changed when setting 'compatible' but IS set to its Vim default when 'compatible' is unset.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文