Update OSX Vim using MacVim - macos

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.

Related

How to install a specific version of vim (+clipboard)

I'm trying to enable copying to OSX's clipboard in vim and most resources I have found say that I need a version of vim with +clipboard. These resources also indicate that this should be as easy as running brew install vim, however, I am stuck with -clipboard even after updating. Any suggestions as to how to force this feature? Do I even need it to achieve the desired behavior?
a brew update brew install vim should give you vim with +clipboard.
However your path probably still points to the old vim. Try that:
alias vim="/usr/local/bin/vim"
probably this will also work: (Not anymore, see the Update)
brew install vim --with-override-system-vim
Addition: I recommend to install it with brew install vim --with-client-server so you will have +xterm_clipboard.
Alternativly you could install macvim which should have all these features already in:
brew install macvim --with-override-system-vim
Update
--with-override-system-vim was removed. The best solution in my opinion is to just add macvim in front of your PATH:
PATH="/Users/user/Applications/MacVim.app/Contents/MacOS/Vim:${PATH}"
export PATH
You can test if vim points to the right instance with which vim

How to use macvim (mvim) in terminal after install with homebrew

I installed macvim with homebrew and when i tip "mvim file" in terminal open the file in another window. Can I fix and open mvim in terminal?
The binary is needed by some plugins (YouCompleteMe), for one.
You can use the binary that is installed with macvim. By default, it's
/usr/local/Cellar/macvim/8.0-144_3/MacVim.app/Contents/MacOS/Vim
You can simply alias vim to it in your shell config (.bashrc, .zshrc, etc.)
alias vim=/usr/local/Cellar/macvim/8.0-144_3/MacVim.app/Contents/MacOS/Vim
MacVim (mvim) is not a terminal application. If you want to open vim in a terminal, just use "vim" instead.
We want the contents of the MacVim.app package to be in the PATH, but do this cleanly. So here's what I do:
cd /Applications; ln -s ../usr/local/Cellar/macvim/8.1-151_1/MacVim.app
That gets you MacVim in /Applications, via a symlink that can be updated when the package is upgraded. Then add this to the PATH in the shell startup file:
PATH=/Applications/MacVim.app/Contents/bin:$PATH
Then when you upgrade you just change the symlink in /Applications and everything still works nicely.

How do I get autochdir to work on a Mac when running Vim from the terminal?

In MacVim autochdir works without a problem. However, lately I've been running iTerm2 (full screen with split) for coding and the lack of autochdir is really bothering me. Any solutions? Thanks.
What do you mean by "the lack of autochdir"? It works fine both in CLI and in GUI.
If you have set autochdir in your ~/.vimrc this feature will work the same way whether you are in MacVim or iTerm2 or Terminal or whatever.
But I suspect you are changing dirs in an iTerm2 split and expecting Vim to somehow learn about that change and change its pwd accordingly. Am I right? "Unfortunately" Vim doesn't know about the second iTerm2 split and can't react to your cd there.
In the terminal:
> which vim
If it says /usr/bin/vim, you're using the mac base installation. This is an old version of vim and doesn't support autochdir. You'll need a newer version.
Check if you have another installation of vim by running:
> /usr/local/bin/vim
If so, add /usr/local/bin to your $PATH before /usr/bin
If not, install it:
> brew install vim

upgrading console emacs (/usr/bin/emacs) on Mac

I extensively use /usr/bin/emacs in Terminal.
I have Emacs 22 and I'd like to upgrade it to 23. I wonder how to do it.
Googling "emacs download mac" gives me Emacs.app which has its own window and user interface, but I don't want that.
I am not sure how I have /usr/bin/emacs in the first place, maybe it came with Mac OS?
You can run the Emacs.app version in a terminal like this:
/Applications/Emacs.app/Contents/MacOS/Emacs -nw
In my .cshrc file, I use an alias to make this easier to invoke:
alias enw '/Applications/Emacs.app/Contents/MacOS/Emacs -nw'
It is a standard editor included with OS X and a lot of other *nix systems along with vi/vim, and pico. Personally i wouldnt upgrade the pre-installed one. I would install from Macports, Fink, or Homebrew or compile from source myself to a different location (like /usr/local).
Install emacs from macports.
% sudo port install emacs
Then launch it from the terminal
Or you can install Emacs.app, follow the instructions here to create a ~/bin/emacs script and then launch as emacs -nw or any other options.
#!/bin/sh
exec /Applications/Emacs.app/Contents/MacOS/Emacs "$#"
I was on this same search and ended up installing with Homebrew so I could get the latest version along with several libraries, as described in this answer at the Emacs Stack Exchange site:
Nowadays, I use just GNU Emacs snapshot builds. These have reasonably good OS X support, and are by far the easiest to install, and best supported by the community.
I used to get them from Emacs for Mac OS X, but now I use Homebrew, because it supports more libraries, notably GNU TLS for encrypted network connections.
All in all: Use brew install emacs --HEAD --use-git-head --with-cocoa --with-gnutls --with-rsvg --with-imagemagick :).
(Note that GNU Emacs is what comes preinstalled on Mac OS X, at least on mine as of 10.10.5)
This added a new Emacs binary at /usr/local/bin/emacs, leaving the existing installation and /usr/bin/emacs in place.
I created a symlink in /usr/local/bin pointing to the new version of emacs which was in Applications/Emacs.app/Contents/MacOS/
For those who installed Emacs from source (or any other way that doesn't overwrite command line called emacs) and want to use this version in the command line, I suggest one of these two approaches:
ln -s ~/path/to/cloned/emacs/src/emacs /usr/local/bin/emacs
make sure /usr/local/bin is in your $PATH and located before /usr/bin, by executing echo $PATH
if it is not, add line export $PATH=/usr/local/bin:$PATH to the file ~/.bash_profile, then refresh $PATH by executing in the terminal source ~/.bash_profile
add ~/path/to/cloned/emacs/src to your $PATH.
for example, add line export $PATH=~/path/to/cloned/emacs/src:$PATH to the file ~/.bash_profile, then refresh $PATH by executing in the terminal source ~/.bash_profile
And yes, MacOS is shipped with many packages pre-installed. But, unfortunately, usually with outdated ones and no official package manager to easily upgrade those libraries. That's actually why we have Homebrew, Macports, maybe others: they serve us as MacOS package managers.

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