267

I have MacVim installed and I am trying to set it up as the editor for Git (version control), but I can't run 'mvim' from the command line as it isn't recognised. How do I setup mvim so I can run it from Terminal?

Dave Mooney
  • 773
  • 8
  • 24
Fred
  • 4,359
  • 4
  • 22
  • 21
  • 3
    Try `vim` from the command-line. – pavium Jan 13 '10 at 11:17
  • 4
    Disclaimer: this would work for Linux so I suppose it is similar on a Mac. Try to see the path (use "`echo $PATH`") and add the folder to the MacVim executable to it if it's not there already (use "`export PATH=$PATH:path/to/folder`"). Mind the `$` signs, they are important! – laura Jan 13 '10 at 11:18

12 Answers12

217

I don't think I'd to add anything to the path, did

brew install macvim

mvim -v

should then open macvim in the terminal, you can also go ahead and alias that

alias vim='mvim -v'
Swapneel Patil
  • 2,303
  • 1
  • 15
  • 6
  • 39
    Anyone reading this today using homebrew you'll have to run `brew linkapps` after installing macvim. – Aaron Lake Sep 29 '11 at 18:20
  • 1
    The '-v' option works if you've installed from source or from download as well as shown in other answers. – Bryan Head Oct 17 '12 at 01:37
  • 7
    `brew linkapps --system` if you want it in your /Applications folder. – mk12 May 26 '13 at 20:07
  • If running `brew linkapps` didn't help, also run `brew doctor` and watch for macvim-related warning messages - you may need to run `brew link --overwrite macvim` if suggested. – Art Jul 11 '16 at 12:42
  • With this -v flag for some reason changing the font doesn't work. – Ixx Apr 01 '18 at 11:41
192

There should be a script named mvim in the root of the .bz2 file. Copy this somewhere into your $PATH ( /usr/local/bin would be good ) and you should be sorted.

Gordon Robertson
  • 2,473
  • 1
  • 15
  • 8
  • 9
    Where do you find the bz2 file? – jnthnclrk Mar 07 '11 at 20:13
  • 2
    A year ago that was what you got when you downloaded MacVim. Now it's a.tbz file, but the script is still there. – Gordon Robertson Mar 09 '11 at 10:39
  • I also can't find where macvim or the bz2 file is – Michael Durrant Mar 06 '12 at 15:55
  • 6
    You can locate the file by using find from your root directory. `sudo find . -name mvim` Mine was in /Applications/MacVim-snapshot-64/mvim. – tltjr Aug 26 '12 at 21:32
  • `mvim` can also be had directly from [source](https://github.com/b4winckler/macvim/blob/master/src/MacVim/mvim). – Clay Bridges Sep 05 '12 at 14:55
  • 19
    Since mvim is simply a shell script, you can download it directly from the MacVim source at GitHub here: https://raw.github.com/b4winckler/macvim/master/src/MacVim/mvim – Brad Parks Sep 26 '12 at 19:43
  • 1
    It's now located in the DMG you download. – studgeek May 27 '13 at 21:56
  • Sorry for last incorrect comment. I left correcting edit open and it expired after 5 minutes (I hate that limit). mvim is actually located in the TBZ which also contains the MacVim.app which you get from the normal [downloads location](https://code.google.com/p/macvim/downloads/list). Personally I think mvim should be inside the MacVim.app bundle though (see this [thread](https://groups.google.com/forum/?fromgroups=#!searchin/vim_mac/mvim$20location/vim_mac/S1jCDYPmYx0/wXKwu1IEb5AJ) for discussion). – studgeek May 27 '13 at 22:04
  • 7
    As per :help mvim I had to add `/Applications/MacVim.app/Contents/bin` to my path then it worked fine. – hraynaud Sep 22 '17 at 18:21
106

If you go the brew route, the best way to install would be:

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

That will provide mvim, vim, vi, view, etc. in /usr/local/bin (all symlinked to the copy in the Cellar). This also removes the need to create any aliases and also changes your vi, vim, etc. to all use the same Vim distribution as your MacVim.

Jimmy C
  • 7,334
  • 9
  • 37
  • 54
Sean Chou
  • 1,229
  • 1
  • 9
  • 3
  • Whilst the `--override-system-vim` did create some of the symlinks for me, it failed to override `/usr/bin/vim` and `/usr/bin/vi` and so I still had to manually `alias` these in my `.profile`. – davetapley Feb 08 '12 at 18:49
  • 12
    Dave, that sounds like a PATH problem, /usr/local/bin needs to be first in your PATH. This answer, pointing at brew, should be the number one answer, as it gets you everything you need. – Jason Yanowitz Feb 16 '12 at 00:03
  • 3
    fyi running `brew doctor` should notify you of any PATH or configuration issues for brew. – Andrew Aug 02 '12 at 15:43
  • Awesome! Thanks for posting this. I added --override-system-vim and didn't even realize how useful it would be. – xer0x Mar 28 '14 at 02:25
  • This did not work for me, not sure that this argument still works?? – ftrotter Nov 05 '19 at 20:55
44

In addition, if you want to use MacVim (or GVim) as $VISUAL or $EDITOR, you should be aware that by default MacVim will fork a new process from the parent, resulting in the MacVim return value not reaching the parent process. This may confuse other applications, but Git seems to check the status of a temporary commit message file, which bypasses this limitation. In general, it is a good practice to export VISUAL='mvim -f' to ensure MacVim will not fork a new process when called, which should give you what you want when using it with your shell environment.

jmlane
  • 1,961
  • 1
  • 15
  • 24
hakamadare
  • 1,494
  • 1
  • 11
  • 13
38

If you already have macVim installed: /Applications/MacVim.app/Contents/MacOS/Vim -g will give you macVim GUI.

just add an alias.

i use gvim because that is what i use on linux for gnome-vim.

alias gvim='/Applications/MacVim.app/Contents/MacOS/Vim -g'

gcb
  • 12,288
  • 7
  • 58
  • 86
  • 1
    Also using `alias vim=/Applications/MacVim.app/Contents/MacOS/Vim` is a great idea. Then you don't need to install MacVim via either MacPorts or Homebrew to update Vim in your terminal, you can just install the release packages from the GitHub release page. – w0rp Apr 19 '17 at 08:59
  • 1
    Note: also useful if homebrew refuses to install macvim because you're staying on "this old version" of macOS for whatever reason. :) – tekHedd May 17 '20 at 18:30
  • 1
    Thanks for that tip, @tekHedd. I'm staying on "this old version" of macOS because I have 32-bit versions of expensive software that I don't want to replace and which has been converted to a subscription model, so I'm keeping the "old" OS so I can run the "old" software that I paid for "in perpetuity" for as long as I reasonably can. YMMV. – August Mohr Nov 26 '20 at 08:02
26

Assume MacVim is installed in the Application folder.

Instead of adding MacVim path to your environment, create a link by typing this in terminal:

sudo ln -s /Applications/MacVim.app/Contents/bin/mvim /usr/local/bin/mvim

Then, open a new terminal window/tab and type mvim.

ccerhan
  • 552
  • 5
  • 7
18

If you have homeBrew installed, this is all you have to do:

brew install macvim
brew linkapps

Then type mvim in your terminal to run MacVim.

k1eran
  • 3,293
  • 3
  • 38
  • 60
Muhammad Reda
  • 24,289
  • 12
  • 85
  • 99
13

Here's what I did:

After building Macvim I copied mvim to one of my $PATH destinations (In this case I chose /usr/local/bin)

cp -v [MacVim_source_folder]/src/MacVim/mvim /usr/local/bin

Then when you invoke mvim it is now recognised but there is an annoying thing. It opens the visual MacVim window, not the one in terminal. To do that, you have to invoke

mvim -v

To make sure every time you call mvim you don't have to remember to add the '-v' you can create an alias:

alias mvim='mvim -v'

However, this alias will only persist for this session of the Terminal. To have this alias executed every time you open a Terminal window, you have to include it in your .profile The .profile should be in your home directory. If it's not, create it.

cd ~
mvim -v .profile

include the alias command in there and save it.

That's it.

Douglas
  • 159
  • 1
  • 4
  • Tried this but it didn't work for me. VIM_APP_DIR=~/Downloads/MacVim-snapshot-64/MacVim.app $ mvim -v x.x Sorry, cannot find MacVim.app. Try setting the VIM_APP_DIR environment variable to the directory containing MacVim.app. – Michael Durrant Mar 06 '12 at 16:09
  • This works when you build MacVim from source, https://github.com/macvim-dev/macvim/blob/master/README_mac.txt, thanks @douglas – mbenegas Nov 04 '15 at 17:45
  • 1
    Probably better to `ln -s` it than `cp` it. – nnutter Jul 24 '17 at 17:23
  • 1
    With this `-v` flag changing the font doesn't work. `-v` enables vi mode. Can imagine that other things don't work in this mode, besides setting a custom font. – Ixx Apr 01 '18 at 11:47
11

I'm adding Bard Park's comment here for that was the real answer for me:

Since mvim is simply a shell script, you can download it directly from the MacVim source at GitHub here: http://raw.github.com/b4winckler/macvim/master/src/MacVim/mvim

OscarRyz
  • 184,433
  • 106
  • 369
  • 548
  • /usr/local/bin was in my PATH, but the bin folder was absent. I had trouble working directly in /usr/local, (probably a permissions issue), so I created a bin directory in my Documents folder. There I created an mvim file, into which I copied the contents of Bard Park's link. I dragged the bin folder with the mvim script to /usr/local. I was asked for my password, then allowed to place the mvim script where I wanted it. But the script didn't run yet. I entered: sudo chmod 755 mvim to give the script execute permissions. Now from the command line when I type mvim filename, MacVim launches. – Jerry Frost Nov 06 '15 at 18:50
  • In order to drag the bin folder into /usr/local, first I entered: open . from the command line in /usr/local. Doing so brings up the finder GUI for that file location. – Jerry Frost Nov 06 '15 at 19:39
8

I'd seriously recommend installing MacVim via MacPorts (sudo port install MacVim).

When installed, MacPorts automatically updates your profile to include /opt/local/bin in your path, and so when mvim is installed as /opt/local/bin/mvim during the install of MacVim you'll find it ready to use straight away.

When you install the MacVim port the MacVim.app bundle is installed in /Applications/MacPorts for you too.

A good thing about going the MacPorts route is that you'll also be able to install git too (sudo port install git-core) and many many other ports. Highly recommended.

ianmjones
  • 3,100
  • 1
  • 21
  • 23
  • 1
    Thanks I'll give this a go. I installed MacVim and Git using the UI installers. But its looking like Macports is the way to go. – Fred Jan 13 '10 at 18:44
  • 56
    Don't use mac port versions unless you absolutely need to. It installs all the dependency libraries ignoring darwin native ones. This can i.e. replace your perl 5.10 with 5.8 in path etc. Check homebrew (brew) system instead. – Slava Nadvorny May 26 '10 at 14:03
  • 3
    @SlavaNadvorny maybe true when this was written. I currently have a development environment with MacVim, scipy, haskell, multiple versions of erlang, python and perl all functioning properly with macports. The same was not possible with brew (at this time this was written). I do like brew's non-sudo install and wished it worked in this case. –  Mar 05 '12 at 16:08
  • Using homebrew works great too `brew install macvim`. – Chev Nov 21 '13 at 19:40
2

For Mac .app bundles, you should install them via cask, if available, as using symlinks can cause issues. You may even get the following warning if you brew linkapps:

Unfortunately brew linkapps cannot behave nicely with e.g. Spotlight using either aliases or symlinks and Homebrew formulae do not build "proper" .app bundles that can be relocated. Instead, please consider using brew cask and migrate formulae using .apps to casks.

For MacVim, you can install with:

brew cask install macvim

You should then be able to launch MacVim like you do any other macOS app, including mvim or open -a MacVim from a terminal session.

UPDATE: A bit of clarification about brew and brew cask. In a nutshell, brew handles software at the unix level, whereas brew cask extends the functionality of brew into the macOS domain for additional functionality such as handling the location of macOS app bundles. Remember that brew is also implemented on Linux so it makes sense to have this division. There are other resources that explain the difference in more detail, such as What is the difference between brew and brew cask? so I won't say much more here.

Ryan H.
  • 5,418
  • 4
  • 34
  • 43
  • Could we add some clarity about what the difference between using the cask install vs not cask install? Hard to tell what the differences are when both cask and not cask install commands work... – ftrotter Nov 05 '19 at 20:55
  • I added a short blurb but I don't know all the details so I didn't go into detail. – Ryan H. Nov 07 '19 at 15:05
2

This works for me:

λ brew link --overwrite macvim
Linking /usr/local/Cellar/macvim/8.0-146_1... 12 symlinks created
AurevoirXavier
  • 1,030
  • 1
  • 8
  • 17