Setting alias to use Macvim in terminal instead of standard Vim

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/"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-vimdoesn't work for me as it also requires to install GUI version of XCode that is too heavy (~5Gb)

2

1 Answer

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/"

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/

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/

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like