Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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

4 Answers 4

up vote 80 down vote accepted

I believe this is what you're looking for:

brew install macvim --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.

share|improve this answer
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  
+1 It's nice finding hidden gems in homebrew. –  Adam Lewis Sep 12 '11 at 1:09
1  
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? –  Ben Mezger 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 at 5:42

The Vi command line switch works.

alias vim='mvim -v'

share|improve this answer

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.

share|improve this answer
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

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"
share|improve this answer
    
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
    
For me this was in /Applications. Nice alias! –  user72923 Sep 25 '12 at 22:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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