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)
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 ;; esacAny 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/tvimwill 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/vimjust 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/datethe 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/datesimilarly
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/afterbut 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
whichdoesn't shows it - you can use the provided
mvimjust hardlink it to another name