23

I'm seeing something very odd, and honestly I'm stumped.

The version of vim that comes with mac is outdated (7.3 instead of 7.4). I'm trying to install vim from homebrew, and I want to use that one instead of the default apple version.

I ran "brew install vim". It installed correctly in /usr/local/bin/vim. All good.

When I run "which vim", it prints "/usr/local/bin/vim". The Apple version of vim is installed at /usr/bin/vim. So the which command is telling me that I'm using the homebrew version of vim.

However, when I actually run vim, it still runs the Apple version

$ vim --version
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Jul  9 2015 23:58:42)
Compiled by [email protected]
...

If I run the homebrew version explicitly, I see this:

$ /usr/local/bin/vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct 23 2015 18:16:35)
MacOS X (unix) version
Included patches: 1-898
Compiled by Homebrew
...

I even tried moving /usr/bin/vim to /usr/bin/vim73 to try to force using the homebrew version. However, when I did this, here is what I see when I try to run vim:

$ vim --version
-bash: /usr/bin/vim: No such file or directory
$

What is going on? How can I get it to run the homebrew version of vim?

7
  • Do you have an alias? Use type instead of which to check. In bash which is not a shell builtin, but type is.
    – janm
    Commented Oct 24, 2015 at 1:56
  • The other obvious problem is the hash table if you haven't restarted your shell: hash -l shows the contents of the hash table in bash.
    – janm
    Commented Oct 24, 2015 at 2:00
  • Ah thanks! When I type "type vim", I see "vim is hashed (/usr/bin/vim)". When I type "hash -l", I do see vim in the list.
    – kgreenek
    Commented Oct 24, 2015 at 2:03
  • To fix it the hacky way, I added 'alias vim="/usr/bin/local/vim"' to my .bash_profile. That seems to work. Is there a nicer way?
    – kgreenek
    Commented Oct 24, 2015 at 2:04
  • 1
    Don't add an alias, no need to modify .bash_profile. Let the path do it for you. A fresh shell will get a fresh hash table, or just do hash -r to clear the hash table and let it get built again.
    – janm
    Commented Oct 24, 2015 at 2:08

2 Answers 2

57

Start a new shell session and it’ll work.

Bash caches executables’ paths so when you run vim it looks at your PATH to find the first executable with this name. It caches it and the second time you run vim it remembers vim is actually /usr/bin/vim and runs that.

Since you haven’t restarted your Bash session its cache is still the same; hence the error you’re seeing. It has nothing to do with the way you installed vim.

If you don’t want to start a new shell session, you can run hash -r to tell Bash to clear its executables memory.

4
  • 1
    This solved it for me. Thanks @bfontaine - you the real MVP.
    – jhliberty
    Commented Feb 19, 2016 at 23:04
  • Perfect. Exactly what I needed to fix my vim +clipboard on OSX! Commented Jan 25, 2018 at 0:57
  • 1
    If you want to stay in the same window/tab/whatever, exec bash is an easy way to get a new shell session in the same place. Commented Sep 20, 2018 at 20:54
  • 1
    @jeremysprofile You can also run hash -r to clear the cache while keeping the same session.
    – bfontaine
    Commented Sep 21, 2018 at 8:25
3

You forgot an argument:

$ brew install vim --override-system-vi
5

Not the answer you're looking for? Browse other questions tagged or ask your own question.