104

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.

9 Answers9

139

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.

kejadlen
  • 1,741
19

The Vi command line switch works.

alias vim='mvim -v'

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"
Wuffers
  • 19,619
4

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

CBHacking
  • 6,404
Diego
  • 141
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

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.

Arda
  • 1,600
  • 1
  • 13
  • 12
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
Alan Dong
  • 193
0

I was able to install the override for vim using:

brew install macvim -- --with-override-system-vim
neogeo
  • 1
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 )

Kay
  • 1,331