103

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.

3
  • What's the difference between MacVim console vim and just regular vim in Terminal?
    – hobbes3
    Mar 24, 2012 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, 2012 at 3:10
  • The vim that ships with OS X also doesn't support the freakin' clipboard.
    – Thanatos
    Feb 23, 2017 at 23:41

9 Answers 9

138

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.

8
  • 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! Sep 11, 2011 at 21:31
  • 2
    Technically, this is a hidden gem in the vim formula, rather than homebrew itself. :)
    – kejadlen
    Sep 12, 2011 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, 2013 at 11:59
  • 4
    This apparently needs the full Xcode installed via the app store (and not just the command line tools).
    – ScoBe
    Jun 3, 2015 at 11:19
  • 5
    This no longer works, because homebrew has removed all formula options going forward. discourse.brew.sh/t/…
    – Fadecomic
    Feb 19, 2019 at 20:39
19

The Vi command line switch works.

alias vim='mvim -v'

1
  • Best answer right here.
    – e_x_p
    Sep 25, 2017 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"
4
  • 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. Sep 11, 2011 at 2:32
  • Ahh, alright. Fixed!
    – Wuffers
    Sep 11, 2011 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... Sep 11, 2011 at 2:47
  • 1
    For me this was in /Applications. Nice alias!
    – user72923
    Sep 25, 2012 at 22:56
4

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

1
  • 1
    No longer works.
    – JESii
    May 9, 2019 at 13:31
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.

6
  • 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). Sep 11, 2011 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, 2011 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. Sep 11, 2011 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, 2011 at 3:04
  • 1
    :) My mind jumped to the worst case (local removed). You should be fine with user local.
    – Adam Lewis
    Sep 11, 2011 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.

1
  • 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. Mar 17, 2015 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
0

I was able to install the override for vim using:

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

I created a shell script to link macvim as system vim commands (vim, view, vimdiff, gvim, gview, gvimdiff) without using homebrew:

Note it installs to your home directory ~/.local/bin. So you'll need to ensure that's on your PATH

#!/bin/sh

MVIM_DIR="/Applications/MacVim.app/Contents/bin"
DEST_DIR="$HOME/.local/bin"
mkdir -p "$DEST_DIR"

(
cd "$MVIM_DIR" || {
    echo "Cannot change to dir $MVIM_DIR"
    exit 2
}

for fn in vim vimdiff view gvim gvimdiff gview; do
    target="$(pwd)/$fn"
    echo "Linking $target into $DEST_DIR..."
    ln -sf "$target" "$DEST_DIR"
done
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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