I want to use MacVim console app instead of a standard vim. In order to accomplish that I try to set alias:

alias vim="/usr/local/Cellar/macvim/8.0-119_1/MacVim.app/Contents/MacOS/Vim" But for some reasons alias command doesn't work and each time I execute which vim it doesn't change and always shows '/usr/local/bin/vim' as a path. What's the matter?

Installing Macvim by brew install macvim --with-override-system-vim doesn't work for me as it also requires to install GUI version of XCode that is too heavy (~5Gb)

  • 1
    Just a note. MacVim comes with a bash script mvim. So, you start MacVim using mvim file. – jm666 Mar 15 '17 at 23:01
  • @jm666 correct, if you want to launch GUI version you start mvim, but MacVim also has console version that lies in MacVim folder according to the path I specified – Alex Smirnov Mar 16 '17 at 19:01

The mvim is universal starting (bash) script for the MacVim. It works based on his own name, e.g if it's name starts with m or g will start the GUI version, otherwise the console version.

You can see this in the mvim source:

case "$name" in m*|g*|rm*|rg*) gui=true ;; esac

Any other name will start the console version. So, it is enough to create an hard-link with the original mvim. For example, if your mvim is in the /usr/local/bin/mvim then

sudo ln /usr/local/bin/mvim /usr/local/bin/tvim

will create the tvim and the tvim command will start the console version of the MacVim. Of course, you can also create the link to vim like

sudo ln /usr/local/bin/mvim /usr/local/bin/vim

just must ensure that the /usr/local/bin is before the /usr/bin in the your $PATH.

Now to your question:

Shadowing commands with aliases doesn't is the best practice. Anyway, it works. So, your

alias vim="/usr/local/Cellar/macvim/8.0-119_1/MacVim.app/Contents/MacOS/Vim"

will start the MacVim's vim. The which command doesn't shows aliases. You can test it yourself, type directly into terminal:

alias bubu=/bin/date

the which bubu will show nothing, but if you run the bubu command you will get the date.

You can check which command will run using the type. E.g.

type bubu
#bubu is alias /bin/date

similarly

type vim
#will show the /usr/local/Cellar/macvim/8.0-119_1/MacVim.app/Contents/MacOS/Vim

Also, you can check the current variables directly from your running vim, just use the :set runtimepath or :set helpfile will show for the default /usr/bin/vim something like:

... /usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after

but for your MacVim (in console mode) will show like:

... /usr/local/Cellar/macvim/8.0-119_1/MacVim.app/Contents/Resources/vim/vimfiles

So, finally:

  • your alias probably works, just the which doesn't shows it
  • you can use the provided mvim just hardlink it to another name

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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