98

I installed MacVim using homebrew. (brew install macvim). If I call mvim from cmd, it opens the GUI MacVim.

I would like to make vim call the MacVim's Vim (/Users/user/Applications/MacVim.app/Contents/MacOS/Vim) instead of the system's (/usr/bin/vim) vim. Which is the best way to do it? I know I can do an alias vim="/Users/user/Applications/MacVim.app/Contents/MacOS/Vim" but I don't know if it's the best approach...

EDIT: Guys, thank for all your answers, but indeed, since I'm already using homebrew, using the --override-system-vim is the elegant way to accomplish what I need.

  • What's the difference between MacVim console vim and just regular vim in Terminal? – hobbes3 Mar 24 '12 at 17:38
  • 2
    @hobbes3, the vim that ships with osx does not have ruby or python support compiled in. MacVim's vim does. Which is necessary if you want to use plugins like Command-T – asgeo1 Mar 31 '12 at 3:10
  • The vim that ships with OS X also doesn't support the freakin' clipboard. – Thanatos Feb 23 '17 at 23:41
135

I believe this is what you're looking for:

brew install macvim --with-override-system-vim

This will create vim, vimdiff, etc. symlinks to mvim in /usr/local/bin/vim, and as long as /usr/local/bin is before /usr/bin in your PATH, you'll get the results you're looking for.

Earlier versions of brew used the switch --override-system-vim which was deprecated.

  • 3
    Since I said I'm already using homebrew, I think this is indeed the best option: I didn't know this option was possible. Thanks! – Somebody still uses you MS-DOS Sep 11 '11 at 21:31
  • 2
    Technically, this is a hidden gem in the vim formula, rather than homebrew itself. :) – kejadlen Sep 12 '11 at 18:40
  • I wonder, what if I do an brew remove macvim, will that remove macvim and leave the original vim? Or that will also be gone? – seds Aug 27 '13 at 11:59
  • @BenMezger: Homebrew doesn't touch your original binaries, it installs packages at your /usr/local. So when you remove macvim, you're with original Mac OSX's vim. – Somebody still uses you MS-DOS Sep 27 '14 at 5:42
  • 3
    This apparently needs the full Xcode installed via the app store (and not just the command line tools). – ScoBe Jun 3 '15 at 11:19
20

The Vi command line switch works.

alias vim='mvim -v'

  • Best answer right here. – e_x_p Sep 25 '17 at 19:49
17

You can create an alias in your ~/.bash_profile, just add this line to that file:

alias vim="/Users/user/Applications/MacVim.app/Contents/MacOS/Vim"
  • Actually, it would be alias vim="/Users/user/Applications/MacVim.app/Contents/MacOS/Vim", since I want to link to the MacVim's console vim and not the gui version. – Somebody still uses you MS-DOS Sep 11 '11 at 2:32
  • Ahh, alright. Fixed! – Wuffers Sep 11 '11 at 2:33
  • Since vim is an interactive application, doing an alias that overrides the System's Vim isn't going to be that harmful, I guess... – Somebody still uses you MS-DOS Sep 11 '11 at 2:47
  • 1
    For me this was in /Applications. Nice alias! – user72923 Sep 25 '12 at 22:56
4

brew install macvim --override-system-vim is deprecated. You should use brew install macvim --with-override-system-vim instead.

3

To change the system's default editor add the following to your .bash_profile

export EDITOR=/usr/local/Cellar/macvim/<version>/bin/mvim 

Changing this should allow you to use MacVim for the default editor (even for the app that autolaunch the editor)

EDIT
For normal usage at the terminal, you would still have to use 'mvim' to edit a file. If you still want to type 'vi' on the terminal, I would suggest adding the alias to the .bash_profile as well.

EDIT 2
After seeing the OP's edit, you could prepend the the path of MacVim's vim to the system path. Note I do not think this is the best way because it could effect other system calls as well while making calls at the terminal. So if you really just want it to change when you type 'vim' at the command line then the use of an alias I believe to be the cleanest and safest thing to do.

PATH="/Users/user/Applications/MacVim.app/Contents/MacOS/Vim:${PATH}"
export PATH

Test your settings by using which vim at the terminal.

  • 2
    I don't want to make mvim the default. I want to call MacVim's vim (/Users/user/Applications/MacVim.app/Contents/MacOS/Vim) when I write down vim on terminal instead of system's vim (/usr/bin/vim). – Somebody still uses you MS-DOS Sep 11 '11 at 2:49
  • @Somebody still uses you MS-DOS: Sorry about that, mis-understood your intent (makes a bit more since now viewing your edit). – Adam Lewis Sep 11 '11 at 2:53
  • Hum, but you gave me an idea: if I symlink vim to /usr/local/bin and using the $PATH approach, it may work. – Somebody still uses you MS-DOS Sep 11 '11 at 3:02
  • @Somebody still uses you MS-DOS: Be careful symlinking to a directory that already has vim in it... It might become difficult to know which vim you're going to get. – Adam Lewis Sep 11 '11 at 3:04
  • 1
    :) My mind jumped to the worst case (local removed). You should be fine with user local. – Adam Lewis Sep 11 '11 at 3:15
2

Edit: just install homebrew (worth the hassle!) and brew install vim

My old answer is below:


I don't want to install xcode just for this, also I don't want to use aliases or brew method (which also requires xcode) so I do this:

  1. I first download MacVim from the releases page,
  2. Then I install MacVim by dragging it to my Applications folder,
  3. For terminal usage, there's also a terminal app in the zip, called mvim, I install it by running this command:

    sudo mv mvim /usr/local/bin/vim

  4. And then, I rehash the environment by hash -r (or close and re-open the terminal).

  5. Finally, when I run vim from my terminal I see the updated one "in the console".

I hope this helps someone.

  • I use homebrew for lots of stuff. It's worth the hassle. Having XCode installed but being able to install all I need just by calling brew install is great. – Somebody still uses you MS-DOS Mar 17 '15 at 6:59
1

My two cents, I run this whenever upgraded my python via homebrew.

brew reinstall vim --HEAD --with-cscope --with-lua --override-system-vim
brew reinstall macvim --HEAD --with-cscope --with-lua --override-system-vim

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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