How to run mvim (MacVim) from Terminal?

169,488

Solution 1

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.

Solution 2

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'

Solution 3

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.

Solution 4

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.

Solution 5

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'

Share:
169,488

Related videos on Youtube

Fred
Author by

Fred

Updated on November 08, 2020

Comments

  • Fred
    Fred over 3 years

    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?

    • pavium
      pavium over 14 years
      Try vim from the command-line.
    • laura
      laura over 14 years
      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!
  • Fred
    Fred over 14 years
    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.
  • Slava Nadvorny
    Slava Nadvorny almost 14 years
    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.
  • jnthnclrk
    jnthnclrk about 13 years
    Where do you find the bz2 file?
  • Gordon Robertson
    Gordon Robertson about 13 years
    A year ago that was what you got when you downloaded MacVim. Now it's a.tbz file, but the script is still there.
  • Aaron Lake
    Aaron Lake over 12 years
    Anyone reading this today using homebrew you'll have to run brew linkapps after installing macvim.
  • davetapley
    davetapley about 12 years
    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.
  • Jason Yanowitz
    Jason Yanowitz about 12 years
    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.
  • Admin
    Admin about 12 years
    @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.
  • Michael Durrant
    Michael Durrant about 12 years
    I also can't find where macvim or the bz2 file is
  • Michael Durrant
    Michael Durrant about 12 years
    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.
  • Andrew
    Andrew over 11 years
    fyi running brew doctor should notify you of any PATH or configuration issues for brew.
  • tltjr
    tltjr over 11 years
    You can locate the file by using find from your root directory. sudo find . -name mvim Mine was in /Applications/MacVim-snapshot-64/mvim.
  • user4581301
    user4581301 over 11 years
    mvim can also be had directly from source.
  • Brad Parks
    Brad Parks over 11 years
    Since mvim is simply a shell script, you can download it directly from the MacVim source at GitHub here: raw.github.com/b4winckler/macvim/master/src/MacVim/mvim
  • Bryan Head
    Bryan Head over 11 years
    The '-v' option works if you've installed from source or from download as well as shown in other answers.
  • mk12
    mk12 almost 11 years
    brew linkapps --system if you want it in your /Applications folder.
  • studgeek
    studgeek almost 11 years
    It's now located in the DMG you download.
  • studgeek
    studgeek almost 11 years
    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. Personally I think mvim should be inside the MacVim.app bundle though (see this thread for discussion).
  • Chev
    Chev over 10 years
    Using homebrew works great too brew install macvim.
  • xer0x
    xer0x about 10 years
    Awesome! Thanks for posting this. I added --override-system-vim and didn't even realize how useful it would be.
  • mbenegas
    mbenegas over 8 years
    This works when you build MacVim from source, github.com/macvim-dev/macvim/blob/master/README_mac.txt, thanks @douglas
  • Jerry Frost
    Jerry Frost over 8 years
    /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
    Jerry Frost over 8 years
    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.
  • JackHasaKeyboard
    JackHasaKeyboard almost 8 years
    Well that's how to do it with a fresh installation, I think he's asking how to make an alias when it's already installed.
  • Naidan
    Naidan almost 8 years
    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.
  • Mark
    Mark about 7 years
    Warning: brew linkapps has been deprecated and will eventually be removed!
  • w0rp
    w0rp about 7 years
    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.
  • nnutter
    nnutter almost 7 years
    Probably better to ln -s it than cp it.
  • hraynaud
    hraynaud over 6 years
    As per :help mvim I had to add /Applications/MacVim.app/Contents/bin to my path then it worked fine.
  • User
    User about 6 years
    With this -v flag for some reason changing the font doesn't work.
  • User
    User about 6 years
    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.
  • ftrotter
    ftrotter over 4 years
    This did not work for me, not sure that this argument still works??
  • ftrotter
    ftrotter over 4 years
    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...
  • Ryan H.
    Ryan H. over 4 years
    I added a short blurb but I don't know all the details so I didn't go into detail.
  • tekHedd
    tekHedd almost 4 years
    Note: also useful if homebrew refuses to install macvim because you're staying on "this old version" of macOS for whatever reason. :)
  • August Mohr
    August Mohr over 3 years
    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.