更新Mac OS X上的内置vim

时间:2022-09-10 19:14:46

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

我知道这可能更适合问不同的问题,但是当我尝试在那里添加标签时,没有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.

我考虑过使用水银(我已经用它来做其他事情了),就像这里的说明。

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

但我认为这将是一个重复的安装。尽管我上面提到了“清洁”的要求,“不清洁”的解决方案也是受欢迎的,因为也许真的没有其他的方法。

7 个解决方案

#1


110  

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 $PATH so 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可执行文件,并在终端中使用它。应用程序一样。

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

#2


118  

If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad idea and 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

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:

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

$ # 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 old 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 SHOULD do.

我建议不要安装在/usr/local/bin当你想覆盖二进制文件在工作,因为默认OS X将工作更高的优先级比/usr/local/bin路径,美元和压榨,打开自己的蠕虫....可以这就是你应该做的。

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

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——帮助查看它们。我希望你有一个备份在你这样做之前,虽然,以防出现错误....

#3


47  

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

和Eric一样,我也使用了homebrew,但我使用了默认的配方。所以:

brew install mercurial
brew install vim

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

在重新启动终端homebrew的vim后,应该是默认的。如果不是,则应该更新$路径,使/usr/local/bin位于/usr/ bin之前。在你的个人资料中加入以下内容:

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

#4


6  

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 '

别名sudo =“sudo”

With this change sudo vim will behave as expected!

有了这个更改,sudo vim将按预期运行!

#5


4  

On Yosemite, install vim using brew and the override-system-vi option. This will automatically install vim with the features of the 'huge' vim install.

在Yosemite上,使用brew和over共乘系统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/vim to 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-vi has been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401

编辑:Brew flag——over共乘系统vi已被弃用。改变了——with-override-system-vi。来源:https://github.com/Shougo/neocomplete.vim/issues/401

#6


1  

brew install vim --override-system-vi

安装vim——override-system-vi酿造

#7


1  

This blog post was 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.

这篇博文对我很有帮助。我使用了“自制Vim”解决方案,在我的例子中,它将新版本保存在/usr/ local/bin中。在这一点上,post建议隐藏系统vim,这对我没用,所以我改用了别名。

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

#1


110  

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 $PATH so 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可执行文件,并在终端中使用它。应用程序一样。

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

#2


118  

If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad idea and 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

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:

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

$ # 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 old 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 SHOULD do.

我建议不要安装在/usr/local/bin当你想覆盖二进制文件在工作,因为默认OS X将工作更高的优先级比/usr/local/bin路径,美元和压榨,打开自己的蠕虫....可以这就是你应该做的。

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

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——帮助查看它们。我希望你有一个备份在你这样做之前,虽然,以防出现错误....

#3


47  

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

和Eric一样,我也使用了homebrew,但我使用了默认的配方。所以:

brew install mercurial
brew install vim

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

在重新启动终端homebrew的vim后,应该是默认的。如果不是,则应该更新$路径,使/usr/local/bin位于/usr/ bin之前。在你的个人资料中加入以下内容:

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

#4


6  

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 '

别名sudo =“sudo”

With this change sudo vim will behave as expected!

有了这个更改,sudo vim将按预期运行!

#5


4  

On Yosemite, install vim using brew and the override-system-vi option. This will automatically install vim with the features of the 'huge' vim install.

在Yosemite上,使用brew和over共乘系统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/vim to 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-vi has been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401

编辑:Brew flag——over共乘系统vi已被弃用。改变了——with-override-system-vi。来源:https://github.com/Shougo/neocomplete.vim/issues/401

#6


1  

brew install vim --override-system-vi

安装vim——override-system-vi酿造

#7


1  

This blog post was 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.

这篇博文对我很有帮助。我使用了“自制Vim”解决方案,在我的例子中,它将新版本保存在/usr/ local/bin中。在这一点上,post建议隐藏系统vim,这对我没用,所以我改用了别名。

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