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

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.

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 install libX11 on OSx 10.9?

I am trying to install ROOT (cern.root.ch). When I run ./configure , I get a message that libX11 is missing and must be installed.
I did some research and found that I need to install
) XQuartz (I already have the latest version.)
) Command line tools in Xcode.
I tried installing Command Line Tools from apple's developer website. The installation goes through smoothly but how do I know whether it has been installed? I still get libX11 missing error with root's configure command.
I also tried xcode-select --install and it once went through smoothly and then later again gives error saying this package is no longer maintained - or something of that sort.
I understand I may have multiple installations... But I am still facing the problem of not having libX11 and not being able to install ROOT.
Thanks,
Hershal.
This link and the one referenced in it suggests you use homebrew (brew) to install it
$ ruby <(curl -fsS https://raw.github.com/mxcl/homebrew/go)
$ brew doctor
Remember to add the Homebrew directory to your PATH by adding the directory (found with brew --prefix) to your .bashrc, .zshrc or whatever shell file you’re using (.bashrc is the OS X default). We’ll also add the XQuartz binaries to the PATH in case anything needs them in the future.
export PATH=/usr/local/bin:/opt/X11/bin:$PATH
Start a new Terminal session to pick up the changes.
Now that Homebrew is installed, we can use it to install the required dependencies. Each may take some time as Homebrew generally compiles from source.
$ brew install gfortran # Fortran compiler
$ brew install python # Python interpreter
$ brew install pcre # Regular Expressions library
$ brew install fftw # Fast Fourier Transforms
$ brew install cmake # Cross-platform make
install root
$ brew tap homebrew/science
$ brew install --with-cocoa root
You don't say whether you have installed XCode as well as the commandline tools but I think you will need it

Patch Vim with the breakindent patch on OS X with Homebrew

I'm on OS X 10.7 with Vim 7.3.
I'd like to install the breakindent patch.
Here's a way to do it on Linux with apt-get:
Compiling VIM with breakindent patch.
How do I do this? I suppose it will involve building Vim via Homebrew (which is OK with me).
Use Mercurial to get the latest Vim source code:
$ hg clone https://vim.googlecode.com/hg/ vim
$ cd vim
Grab the patch.
Apply the patch as indicated in the linked thread:
$ patch -p1 < /path/to/breakindent.patch
Configure Vim with the options you need (python/ruby support, custom location, etc.):
$ ./configure --with-features=huge <other options>
Build and install:
$ sudo make && make install
I just modified the Homebrew formula for MacVim to optionally add that patch. If you want to try it out, you can download the formula at https://gist.github.com/4108848 and plunk it in /usr/local/Library/Formula; then install using brew install --with-breakindent-patch macvim.
(EDIT: I used to have a link to my GitHub fork of Homebrew here, but I've decided to delete that fork unless I actually submit anything to Homebrew. The old formula could optionally add a patch that's been added to the main Vim since then.)
As of June 25th 2014, VIM includes the breakindent patch by default – finally :-)
For more info, see https://retracile.net/blog/2014/07/18/18.00
If you're installing from Homebrew, use:
brew install macvim --with-features=huge --override-system-vim --HEAD

Installing vim with ruby support (+ruby)

I'm trying to get command-t installed for vim but my current version of vim doesn't have the (+ruby) flag. The command "which ruby" shows that ruby is installed.
What do I need to do in order to activate the +ruby flag in vim?
Also, what does the +ruby flag technically mean?
Some package provides vim-ruby on Ubuntu, for example vim-nox.
simply:
sudo apt-get install vim-nox;
will get you vim with ruby, as well as compiled in "support for scripting with Perl, Python, Ruby, and TCL but no GUI."
sudo apt-get install vim-rails
will install a "selection of vimscripts that make editing Ruby on Rails applications extremely easy." but as it depends on vim-full and vim-addon-manager, it will also install the vim-gnome version of the GUI, that is "a version of vim compiled with a GNOME2 GUI and support for scripting with Perl, Python, Ruby, and TCL."
I think "Compiling Vim With Ruby Integration On Snow Leopard" might actually help. I'm on exactly same boat at the moment.
Ok... got it to work. Took me like half hour or so.
This should help (I got Ubuntu):
sudo apt-get install mercurial
hg clone https://vim.googlecode.com/hg/ vim
cd vim
./configure --enable-rubyinterp
make
sudo make install
To test if things look fancy:
vim --version | grep ruby
Should return something like:
-python3 +quickfix +reltime -rightleft +ruby +scrollbind +signs +smartindent
Ruby should have plus now. Another trick to test it - enter vim and hit :ruby 1. Should not fail.
On mac os x, assuming you have Homebrew installed:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/vim.rb
This version of vim has ruby support enabled
Source: http://blog.jerodsanto.net/2011/08/brew-install-vim/
EDIT: edited the url, thanks #david-xia for mentioning the change
UPDATE: Apparently, homebrew vim now comes with ruby support enabled by default so you just need to do brew install vim (see comment below)
If there isn't a Ruby enabled Vim available for your operating system, you'll have to recompile. This is very easy and there are some instructions on the Vim website I believe. If you're on Linux, you use configure to choose what you want. Have a look at the output of:
./configure --help
in the Vim source directory. Read it carefully, there are a lot of options in there. The main one you want is --enable-rubyinterp, but you may also want to add --with-features=HUGE among others. As I said, read the help provided.
when you run ./configure you need to add the folowing --enable-rubyinterp
./configure --enable-rubyinterp
On Mac OS X, I find that the easiest is to install MacVim with brew install macvim which includes +ruby. And then symlink /usr/local/bin/vim to /usr/local/bin/mvim. That way to get a recent Vim version, with the huge feature set, +ruby, both GUI and command line vim just using the standard HomeBrew repository. No need for external repository like in Pierre answer
To avoid issues it's better to use the use the system ruby during installation so:
rvm use system
brew install macvim
ln -s /usr/local/bin/mvim /usr/local/bin/vim
Flag +ruby means that vim is compiled with ruby support and linked against ruby interpreter library. You cannot get this flag without recompiling vim or installing another version which is compiled with this flag.
Pulling the vim source using Mercurial and changing into the directory will give you the ability to configure your vim install before you compile it.
hg clone https://vim.googlecode.com/hg/ vim
cd vim
./configure --enable-rubyinterp
The --enable-xxinterp option can be used for Python, Perl, or any other language that Vim will support. Just type it in where the xx is and it will work.
Running the help option with the configure command will allow you to see all of the configuration options.
./configure --help
Under Windows you can install Vim from here:
http://sourceforge.net/projects/cream/files/Vim/
Version 7.3.3 seems to be compiled with Ruby support (see release notes file). The newest 7.3.x currently is not.
Installing vim-rails will add Ruby (+ruby) support. I just tried and verified that it works and Command-T runs fine now.
sudo apt-get install vim-rails
If you are using MacPorts in OSX, you may try
sudo port install vim +ruby
To specify a different ruby version, you may try
sudo port install vim +ruby18
or
sudo port install vim +ruby19
It looks like you need to have ruby installed before install vim-nox.
This works for me on Ubuntu 18.10
sudo apt-get install ruby rubygems vim-nox
Source: https://junegunn.kr/2013/09/installing-vim-with-ruby-support
If you are lazzy and don't want to recompile you can try to find a package with a vim version including ruby. On debian it's vim-ruby so something like
apt-get install vim-ruby
might work. (I can't try it, I m on mac. On mac , MacVim come with ruby enabled)

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