macos 更新 Mac OS X 上的内置 vim

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7211820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:22:00  来源:igfitidea点击:

Update built-in vim on Mac OS X

macosvim

提问by Kit

I know this might be more appropriate at Ask Different, but as I tried adding tags there, there was no vimtag, only macvim. So I figured I might get a better audience here.

我知道这在 Ask Different 可能更合适,但是当我尝试在那里添加标签时,没有vim标签,只有macvim. 所以我想我可能会在这里得到更好的观众。

In the Terminal, I do the following

在终端中,我执行以下操作

$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jan 31 2010 13:33:49)

When I browse to http://www.vim.org, I see a news item

当我浏览到http://www.vim.org 时,我看到一条新闻

Vim 7.3 released!

Vim 7.3 发布!

How do I update my built-in vim? I would very much like to do it cleanly (i.e. no duplicate installations, or any additional downloads, no macports, etc.)

如何更新我的内置 vim?我非常想干净利落地做(即没有重复安装,或任何额外的下载,没有 macports 等)

I considered using Mercurial (as I already use it for other things), as per the instructions here.

我考虑过使用 Mercurial(因为我已经将它用于其他用途),按照此处的说明。

$ hg clone https://vim.googlecode.com.hg/ vim
$ cd vim/src
$ make

But I think that would make a duplicate installation. Despite my "clean" requirement as mentioned above, "unclean" solutions are also welcome, since maybe there really is no other way.

但我认为这会导致重复安装。尽管我上面提到了“干净”的要求,“不干净”的解决方案也是受欢迎的,因为也许真的没有其他办法。

回答by Robert Martin

If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad ideaand it is not the "clean" way to do it.Why? Well, OS X expects that nothing will ever change in /usr/bin unbeknownst to it, so any time you overwrite stuff in there you risk breaking some intricate interdependency. And, Let's say you do break something -- there's no way to "undo" that damage. You will be sad and alone. You may have to reinstall OS X.

如果我理解正确,你想安装在你现有的 Vim 上,无论好坏:-) 这是一个坏主意,它不是“干净”的方式来做到这一点。为什么?好吧,OS X 预计 /usr/bin 中的任何内容都不会在它不知情的情况下发生变化,因此任何时候您覆盖其中的内容都可能会破坏一些错综复杂的相互依赖关系。而且,假设您确实破坏了某些东西——没有办法“消除”这种损害。你会感到悲伤和孤独。您可能需要重新安装 OS X。

Part 1: A better idea

第 1 部分:一个更好的主意

The "clean" way is to install in a separate place, and make the new binary higher priority in the $PATH. Here is how I recommend doing that:

“干净”的方法是安装在一个单独的地方,并使新的二进制文件在 $PATH 中具有更高的优先级。以下是我建议这样做的方法:

$ # Create the directories you need
$ sudo mkdir -p /opt/local/bin
$ # Download, compile, and install the latest Vim
$ cd ~
$ hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
$ 
$ cd vim
$ ./configure --prefix=/opt/local
$ make
$ sudo make install
$ # Add the binary to your path, ahead of /usr/bin
$ echo 'PATH=/opt/local/bin:$PATH' >> ~/.bash_profile
$ # Reload bash_profile so the changes take effect in this window
$ source ~/.bash_profile

Voila! Now when we use vim we will be using the new one. But, to get back to our old configuration in the event of huge f*ckups, we can just delete the /opt directory.

瞧!现在当我们使用 vim 时,我们将使用新的。但是,为了在出现大量 f*ckups 时恢复到我们的旧配置,我们可以删除 /opt 目录。

$ which vim
/opt/local/bin/vim
$ vim --version | head -n 2
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 27 2011 20:55:46)
MacOS X (unix) version

See how clean this is.

看看这里有多干净。

I recommend not to install in /usr/local/bin when you want to override binaries in /usr/bin, because by default OS X puts /usr/bin higher priority in $PATH than /usr/local/bin, and screwing with that opens its own can of worms.... So, that's what you SHOULDdo.

当你想覆盖 /usr/bin 中的二进制文件时,我建议不要安装在 /usr/local/bin 中,因为默认情况下,OS X 将 /usr/bin 放在 $PATH 中的优先级高于 /usr/local/bin,并且搞砸了这会打开它自己的蠕虫罐头......所以,这就是你应该做的。

Part 2: The "correct" answer (but a bad idea)

第 2 部分:“正确”答案(但一个坏主意)

Assuming you're set on doing that, you are definitely on track. To install on top of your current installation, you need to set the "prefix" directory. That's done like this:

假设您打算这样做,那么您肯定会走上正轨。要在当前安装的基础上安装,您需要设置“前缀”目录。这样做是这样的:

hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
cd vim
./configure --prefix=/usr
make
sudo make install

You can pass "configure" a few other options too, if you want. Do "./configure --help" to see them. I hope you've got a backup before you do it, though, in case something goes wrong....

如果需要,您也可以通过“配置”其他一些选项。执行“./configure --help”来查看它们。不过,我希望你在做之前有一个备份,以防万一出现问题......

回答by romainl

Don't overwrite the built-in Vim.

不要覆盖内置的 Vim。

Instead, install it from source in a different location or via Homebrew or MacPorts in their default location then add this line to your .bashrc or .profile:

相反,从不同位置的源代码或通过 Homebrew 或 MacPorts 在其默认位置安装它,然后将此行添加到您的 .bashrc 或 .profile:

alias vim='/path/to/your/own/vim'

and/or change your $PATHso that it looks into its location before the default location.

和/或更改您$PATH的位置,使其在默认位置之前查看其位置。

The best thing to do, in my opinion, is to simply download the latest MacVim which comes with a very complete vim executable and use it in Terminal.app like so.

在我看来,最好的办法是简单地下载最新的 MacVim,它带有一个非常完整的 vim 可执行文件,并像这样在 Terminal.app 中使用它。

alias vim='/Applications/MacVim.app/Contents/MacOS/Vim' # or something like that, YMMV

回答by Koen.

Like Eric, I used homebrew, but I used the default recipe. So:

像 Eric 一样,我使用自制软件,但我使用了默认配方。所以:

brew install mercurial
brew install vim

And after restarting the terminal homebrew's vim should be the default. If not, you should update your $PATHso that /usr/local/binis before /usr/bin. E.g. add the following to your .profile:

重新启动终端自制软件后,vim 应该是默认值。如果没有,您应该更新您的,$PATH以便/usr/local/bin/usr/bin. 例如,将以下内容添加到您的.profile

export PATH=/usr/local/bin:$PATH

回答by jayeff

A note to romainl's answer: aliases don't work together with sudo because only the first word is checked on aliases. To change this add another alias to your .profile / .bashrc:

romainl 的回答说明:别名不能与 sudo 一起使用,因为只检查别名的第一个单词。要更改此设置,请向您的 .profile / .bashrc 添加另一个别名:

alias sudo='sudo '

alias sudo='sudo '

With this change sudo vimwill behave as expected!

有了这个变化,sudo vim将按预期运行!

回答by Private

On Yosemite, install vim using brewand the override-system-vioption. This will automatically install vim with the features of the 'huge' viminstall.

在 Yosemite 上,使用brewoverride-system-vi选项安装 vim 。这将自动安装具有“巨大”vim安装功能的vim

brew install vim --with-override-system-vi

The output of this command will show you where brew installed vim. In that folder, go down into /bin/vimto actually run vim. This is your command to run vim from any folder:

此命令的输出将显示 brew 安装 vim 的位置。在该文件夹中,进入/bin/vim实际运行 vim。这是从任何文件夹运行 vim 的命令:

/usr/local/Cellar/vim/7.4.873/bin/vim

Then alias this command by adding the following line in your .bashrc:

然后通过在 .bashrc 中添加以下行来为该命令设置别名:

alias vim="/usr/local/Cellar/vim/7.4.873/bin/vim"

EDIT: Brew flag --override-system-vihas been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401

编辑:Brew 标志--override-system-vi已被弃用。更改为--with-override-system-vi. 来源:https: //github.com/Shougo/neocomplete.vim/issues/401

回答by kkelleey

This blog postwas helpful for me. I used the "Homebrew built Vim" solution, which in my case saved the new version in /usr/local/bin. At this point, the post suggested hiding the system vim, which didn't work for me, so I used an alias instead.

这篇博文对我很有帮助。我使用了“Homebrew built Vim”解决方案,在我的情况下,它将新版本保存在 /usr/local/bin 中。此时,帖子建议隐藏系统vim,这对我不起作用,所以我改用别名。

$ brew install vim
$ alias vim='/path/to/new/vim
$ which vim
vim: aliased to /path/to/new/vim

回答by MIA

I just installed vim by:

我刚刚通过以下方式安装了 vim:

brew install vim

now the new vim is accessed by vimand the old vim (built-in vim) by vi

现在新vim被访问,vim旧vim(内置vim)被访问vi

回答by Toothrot

brew install vim --override-system-vi

brew install vim --override-system-vi