The best way to make MacVim's vim (console, not mvim) the default instead of Mac OS X's vim?

101

49

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.

Somebody still uses you MS-DOS

Posted 2011-09-11T02:21:03.373

Reputation: 4 143

The vim that ships with OS X also doesn't support the freakin' clipboard. – Thanatos – 2017-02-23T23:41:25.217

What's the difference between MacVim console vim and just regular vim in Terminal? – hobbes3 – 2012-03-24T17:38:40.760

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 – 2012-03-31T03:10:02.157

Answers

137

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

Posted 2011-09-11T02:21:03.373

Reputation: 1 721

@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 – 2014-09-27T05:42:39.393

4This apparently needs the full Xcode installed via the app store (and not just the command line tools). – ScoBe – 2015-06-03T11:19:13.367

Nope. Does not work. – e_x_p – 2017-09-25T19:34:44.910

High Sierra macOS 10.13 required preliminary step to build properly: sudo xcode-select -s /Applications/Xcode.app/Contents/Developer following this the brew install worked with-override-system-vim. – jimmont – 2018-08-14T16:58:20.773

3

This no longer works, because homebrew has removed all formula options going forward. https://discourse.brew.sh/t/macvim-override-system-vim-even-when-using-bottled-version/1751

– Fadecomic – 2019-02-19T20:39:42.350

3Since 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 – 2011-09-11T21:31:06.570

2Technically, this is a hidden gem in the vim formula, rather than homebrew itself. :) – kejadlen – 2011-09-12T18:40:53.837

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 – 2013-08-27T11:59:24.297

20

The Vi command line switch works.

alias vim='mvim -v'

William Bettridge-Radford

Posted 2011-09-11T02:21:03.373

Reputation: 1 648

Best answer right here. – e_x_p – 2017-09-25T19:49:33.313

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

Posted 2011-09-11T02:21:03.373

Reputation: 16 645

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 – 2011-09-11T02:32:35.837

Ahh, alright. Fixed! – Wuffers – 2011-09-11T02:33:44.283

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 – 2011-09-11T02:47:58.960

1For me this was in /Applications. Nice alias! – user72923 – 2012-09-25T22:56:22.513

4

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

Diego

Posted 2011-09-11T02:21:03.373

Reputation: 41

1No longer works. – JESii – 2019-05-09T13:31:38.730

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.

Adam Lewis

Posted 2011-09-11T02:21:03.373

Reputation: 691

2I 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 – 2011-09-11T02:49:16.617

@Somebody still uses you MS-DOS: Sorry about that, mis-understood your intent (makes a bit more since now viewing your edit). – Adam Lewis – 2011-09-11T02:53:29.473

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 – 2011-09-11T03:02:37.207

@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 – 2011-09-11T03:04:01.843

That's why I'm thinking about /usr/local/bin and not /usr/bin. homebrew uses /usr/local/bin for some formulas so I don't think it's going to be a problem. – Somebody still uses you MS-DOS – 2011-09-11T03:07:57.620

1:) My mind jumped to the worst case (local removed). You should be fine with user local. – Adam Lewis – 2011-09-11T03:15:04.163

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

Posted 2011-09-11T02:21:03.373

Reputation: 1 291

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 – 2015-03-17T06:59:16.343

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

Posted 2011-09-11T02:21:03.373

Reputation: 173