Installing vim with homebrew assistance - macos

I tried to install YouCompleteMe on Mac for vim, but I've been using the system vim which is version 7.3. I tried to update my vim using homebrew by typing brew install vim and everything seemed to be fine.
When I type vim I still see the system vim loading (version 7.3).
I feel like I'm missing a step that's keeping me from using the updated vim I got from homebrew. Does anyone know what I'm missing?
For reference when I type which vim I get the following output /usr/bin/vim. Any help would be greatly appreciated.

Just install vim via homebrew:
brew install vim
Then restart your shell:
exec -l $SHELL
And check the version:
$ vim --version|head -n 1
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Mar 9 2016 19:07:39)

You should probably have done brew install vim --with-override-system-vi. This will replace default vim path.

You're loading your system vim first, as you can see by which vim returning /usr/bin/vim instead of /usr/local/bin/vim.
/usr/local/bin is homebrew's path.
Make sure that your path lists /usr/local/bin before /usr/bin:
/usr/local/bin:/usr/bin
This will allow homebrew's vim to be sourced before the system vim.
To view your path:
echo "$PATH"

Rather than reinstalling vim you can move your current vim to vim73 (or something similar).
First check if /usr/local/bin is present in PATH environment variable. Doing echo $PATH on your terminal should do that.
Install vim with homebrew if you haven't already.
brew install vim
Then move your current vim installation.
mv /usr/bin/vim /usr/bin/vim73
Run which vim to confirm. It should say /usr/local/bin/vim.

brew install vim --with-override-system-vi (missing the with-)

echo 'export PATH=/usr/local/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
Run this command and it will be fixed.

Related

How to revert to system vim after using installing vim with homebrew?

I wanted to upgrade to vim 7.4+ but the macOS system version was 7.3. I used the command brew install vim --override-system-vim however I don't think overriding system defaults is ever a good idea. How can I revert the changes back to the system defaults?
Just remove /usr/local/bin/vi (which is a symbolic link to brew's vi).
Run brew rm vim && brew install vim.
Making the symbolic link is all what --override-system-vim do.
Brew actually doesn't do anything with system vi.

Bash still trying to use uninstalled and unlinked Vim version

I am trying to switch to vim 8. I uninstalled 7.4 and install 8 with homebrew. I am currently stuck with the following error:
$ vim
-bash: /usr/local/Cellar/vim/7.4.1301/bin/vim: No such file or directory
I don't understand what is happening because the linkings seems correct:
$ which vim
/usr/local/bin/vim
$ readlink /usr/local/bin/vim
../Cellar/vim/8.0.0051/bin/vim
I am using iTerm2 as my terminal and I already tried restarting it.
Edit 1: For the installation I removed vim completely using brew uninstall vim and then reinstalled it through homebrew.
Edit 2:
$ brew info vim
vim: stable 8.0.0051 (bottled), HEAD
Vi "workalike" with many additional features
http://www.vim.org/
Conflicts with: ex-vi
/usr/local/Cellar/vim/8.0.0051 (1,710 files, 23.3M) *
Poured from bottle on 2016-10-28 at 11:24:37
Edit 3: brew cleanup also did not yield a result.
Shell aliases / functions may still apply. The which command doesn't see those.
You can check with
$ type vim
vim is aliased to `/usr/local/Cellar/vim/7.4.1301/bin/vim'
Or try invoking Vim with quotes:
$ 'vim'

Update OSX Vim using MacVim

I'm trying to update Vim (for use in Terminal) on my Mac. It's currently running version 7.3, but YouCompleteMe requires Vim 7.3.584, and won't run even though it's installed.
I've tried using a Vim alias in my .bash_profile:
alias vim='/Users/Conor/Applications/MacVim.app/Contents/MacOS/Vim'
However none of my Vim plugins are launched when I run Vim like this, any my vimrc file isn't recognised either.
How can I get this alias to recognise my existing Vim settings? Or is there a better way of upgrading Vim for mac?
The *.tbz that you downloaded from the official page contains a mvim script.
Once you have moved that script somewhere in your $PATH you can start the MacVim GUI like this:
$ mvim filename
and the MacVim CLI like that:
$ mvim -v filename
From there the only thing you need is to change your alias to point to mvim:
alias vim='mvim -v'
The original built-in Vim and its runtime files stay untouched, MacVim uses its own runtime files located in the MacVim.app bundle and both honor your personal config (assuming they are located where they should be: ~/.vimrc and ~/.vim/).
Quick, clean and painless.
If you installed MacVim with HomeBrew you can use
brew install macvim --override-system-vim
If you just want pure vim with python support do:
brew install vim --override-system-vim --HEAD
I had the same issue as you, but this worked like a charm. You complete me works perfectly after this.

turn on/install ctags in Macvim (having installed homebrew, oh-my-zsh, janus)

I installed macvim using homebrew on my Mackbook Pro (lion). once that was installed I installed janus. I also installed oh-my-zsh (if that helps solve this problem).
I can't seem to get ctags working though. In MacVim when I do Tools>Build Tags File I get:
:!ctags -R .
ctags: illegal option -- R
usage: ctags [-BFadtuwvx] [-f tagsfile] file ...
shell returned 1
Press RETURN or type command to continue
How do I get it to work?
Here's some additional info that may help you:
✗ ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Jul 7 2012, 01:00:53
Addresses: <dhiebert#users.sourceforge.net>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
✗ which ctags
/usr/local/bin/ctags
✗ echo $path
/Users/adam/.rvm/gems/ruby-1.9.3-p194#gemset/bin /Users/adam/.rvm/gems/ruby-1.9.3-p194#global/bin /Users/adam/.rvm/rubies/ruby-1.9.3-p194/bin /Users/adam/.rvm/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /usr/X11/bin /Users/adam/.rvm/bin
It definitely looks like Vim is picking up /usr/bin/ctags, which doesn't recognize -R, instead of /usr/local/bin/ctags. This can happen if put /usr/local/bin in your path only for login shells.
You might want to make sure /usr/local/bin gets added to your path in the non-login, non-interactive environment file. I don't use zsh myself, but it looks like that would be .zshenv.
On a mac, by default the path that vim uses and the path that the terminal (bash/zsh) uses are different, so even if you have the correct path set in the terminal, it won't translate to vim correctly, to rectify this situation, you need to run
sudo chmod ugo-x /usr/libexec/path_helper
For more information see: How to use correct ruby in vim ? How to modify $PATH in VIM?.

How to run mvim (MacVim) from Terminal?

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?
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'
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.
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.
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.
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'
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.
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.
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.
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
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.
This works for me:
λ brew link --overwrite macvim
Linking /usr/local/Cellar/macvim/8.0-146_1... 12 symlinks created
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.

Resources