Update built-in vim on Mac OS X

后端 未结 8 801
后悔当初
后悔当初 2020-12-12 08:50

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 g

8条回答
  •  囚心锁ツ
    2020-12-12 09:02

    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.

    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 new one. But, to get back to our old configuration in the event of huge f*ckups, we can just delete the /opt directory.

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

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

提交回复
热议问题