How can i make ZSH use the latest git version? - macos

I am using ZSH with oh-my-zsh on OS X.
Today I used hombrew to update to the latest version of git (1.8.something).
However, if I run
➜ ~ git --version
git version 1.7.10.2 (Apple Git-33)
I see that still an older version is used. On bash everything works fine and the latest version of git is called.
Since I am new to ZSH, any advice on how to set up ZSH to use the "new" git is appreciated!
Best,
Tobi

This means that your $PATH variable isn't set up to include the right git (and everything else homebrew installs).
Try doing echo $PATH from both bash and zsh. You should see at least one difference: the directory where you installed homebrew, probably /usr/local/bin. (It'll either not be in there, or be after /usr/bin, where the Apple-supplied binary lives.)
To fix it, add a line like
export PATH=/usr/local/bin:$PATH
to your ~/.zshenv.

If the PATH modification didn't instantly work, you need to realize that with zsh you need to type "rehash" for zsh to recognize there are new executables in the path. Or just log out and back in.

Compare the outputs of which git (and the outputs of echo "$PATH") in bash and zsh.
The directory containing an up-to-date git is probably not present in $PATH variable for zsh, but it is in bash. It's likely caused by $PATH items being added in your ~/.bashrc and/or ~/.bash_profile file, which zsh doesn't source on startup. If it's so, add the same assignment to PATH to your ~/.zshrc

Related

Upgrading bash on mac

I've tried to upgrade my bash version on my Macbook Pro (Mojave OS). To do this, I've run:
brew install bash
sudo nano /etc/shells # And then added the new bash shell to the bottom of the list.
chsh -s /usr/local/Cellar/bash/5.0.11/bin/bash
After doing this, bash -version still returns version 3 but echo $BASH_VERSION print's version 5. If I try and make an associative array (I think this isn't present in 3), it works, so I assume I am using the new shell. Why has my bash version not updated?
Although you are running your updated version of bash, the command bash is (without a full path) still pointing to the original bundled version: /usr/bin/bash.
Assuming that you actually need to call the command in this form, then you should check the order of locations in $PATH, and make sure that the bin/ folder with the new bash command is in the $PATH list before /usr/bin. Failing that, make an alias in the shell pointing to the new bash.
brew adds the bash executable to /usr/local/bin/ directory.
I think this should work:
brew install bash
sudo nano /etc/shells # And then add /usr/local/bin/bash to the bottom of the list.
chsh -s /usr/local/bin/bash

Git - how do I add the configuration for me to "tab" to get the correct branch or branches if there aren't any matches? [duplicate]

E.g. on a fresh ubuntu machine, I've just run sudo apt-get git, and there's no completion when typing e.g. git check[tab].
I didn't find anything on http://git-scm.com/docs, but IIRC completion is included in the git package these days and I just need the right entry in my bashrc.
On Linux
On most distributions, git completion script is installed into /etc/bash_completion.d/ (or /usr/share/bash-completion/completions/git) when you install git, no need to go to github. You just need to use it - add this line to your .bashrc:
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
In some versions of Ubuntu, git autocomplete may be broken by default, reinstalling by running this command should fix it:
sudo apt-get install git-core bash-completion
On Mac
You can install git completion using Homebrew or MacPorts.
Homebrew
if $BASH_VERSION > 4: brew install bash-completion#2 (updated version)
Pay special care which version of bash you have as MacOS default ships with 3.2.57(1)-release.
add to .bash_profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
For older versions of bash: brew install bash-completion
add to .bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
MacPorts
sudo port install git +bash_completion
then add this to your .bash_profile:
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi
more info in this guide: Install Bash git completion
Note that in all cases you need to create a new shell (open a new terminal tab/window) for changes to take effect.
i had same issue, followed below steps:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
then add the following lines to your .bash_profile (generally under your home folder)
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
source : http://code-worrier.com/blog/autocomplete-git/
Most of the instructions you see will tell you to download
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
and source that in your bash startup script like .bashrc.
But there is a problem with that, because it is referencing the master branch, which is the latest version of git-completion.bash. The problem is that sometimes it will break because it is not compatible with the version of git you've installed.
In fact, right now that will break because the master branch's git-completion.bash has new features that requires git v2.18, which none of the package managers and installers have updated to yet. You'll get an error unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
So the safest solution is to reference the version/tag that matches the git you've installed. For example:
https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash
Note that it has a v2.17. in the URL instead of master. And then, of course, make sure to source that in the bash startup script.
Ubuntu 14.10
Install git-core and bash-completion
sudo apt-get install -y git-core bash-completion
For current session usage
source /usr/share/bash-completion/completions/git
To have it always on for all sessions
echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
Just do this in your ~/.bashrc:
source /usr/share/bash-completion/completions/git
Other answers are telling you to install bash-completion, you don't need to do that, but if you do, then there's no need to source the completion directly. You do one or the other, not both.
A more generic solution is querying the system location as recommended by the bash-completion project:
source "$(pkg-config --variable=completionsdir bash-completion)"/git
See https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
You just need to source the completion script
on my ubuntu there is a file installed here:
source /etc/bash_completion.d/git-prompt
you can follow the links into the /usr/lib/git-core folder. You can find there an instruction, how to set up PS1 or use __git_ps1
macOS via Xcode Developer Tools
Of all the answers currently posted for macOS, this is only mentioned in a very brief comment by jmt...
If you already have the Xcode developer tools installed, then you shouldn't need to download anything new.
Instead, you just need to locate the already-existing git-completion.bash file and source it in your .bashrc. Check the following directories:
/Applications/Xcode.app/Contents/Developer/usr/share/git-core
/Library/Developer/CommandLineTools/usr/share/git-core
Failing that, git itself might be able to help you out. When I run git config as follows, git reports a setting which comes from a gitconfig file located in the same directory as my git-completion.bash:
$ git config --show-origin --list
...
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig credential.helper=osxkeychain
...
or you can always brute-force search your machine and grab some coffee:
$ find / -type f -name git-completion.bash 2>/dev/null
Thus, I have the following insertion for my ~/.bashrc:
# Git shell completion and prompt string on macOS
_git_dir="/Applications/Xcode.app/Contents/Developer/usr/share/git-core"
if [ -f "${_git_dir}/git-completion.bash" ]; then
source "${_git_dir}/git-completion.bash"
fi
if [ -f "${_git_dir}/git-prompt.sh" ]; then
source "${_git_dir}/git-prompt.sh"
fi
unset _git_dir
Note that this sources the git prompt-string script as well, since it resides in the same directory.
(Tested in macOS Catalina)
May be helpful for someone:--
After downloading the .git-completion.bash from the following link,
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
and trying to use __git_ps1 function, I was getting error as--
-bash: __git_ps1: command not found
Apparently we need to download scripts separately from master to make this command work, as __git_ps1 is defined in git-prompt.sh . So similar to downloading .git-completion.bash , get the git-prompt.sh:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
and then add the following in your .bash_profile
source ~/.bash_git
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
export PS1='\W$(__git_ps1 "[%s]")>'
fi
source ~/.bash.git will execute the downloaded file and
export PS1='\W$(__git_ps1 "[%s]") command will append the checkout out branch name after the current working directory(if its a git repository).
So it will look like:-
dir_Name[branch_name] where dir_Name is the working directory name and branch_name will be the name of the branch you are currently working on.
Please note -- __git_ps1 is case sensitive.
Arch Linux
Source /usr/share/git/completion/git-completion.bash in one of the bash startup files.
For example:
# ~/.bashrc
source /usr/share/git/completion/git-completion.bash
You may be able to find the script in other locations like /usr/share/bash-completion/completions/git but these scripts did not work for me.
Mac M1
For those that are using Mac M1 environment, I was able to install via homebrew:
brew install bash-completion
Then added to my ~/.bash_profile or ~/.bashrc (whatever you use):
[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"
You may need to update the version number (1.3_3). You'll just need to look it up in that directory. I would love to know if there's a better way.
Windows
How it works for me finally on Windows 10 command line (cmd):
Install Clink
Copy git-autocomplete.lua file into C:\Users\<username>\AppData\local\clink directory
Restart Windows
Ubuntu
There is a beautiful answer here. Worked for me on Ubuntu 16.04
Windows
Git Bash is the tool to allow auto-completion. Not sure if this is a part of standard distribution so you can find this link also useful.
By the way, Git Bash allows to use Linux shell commands to work on windows, which is a great thing for people, who have experience in GNU/Linux environment.
On Ubuntu 22.04 just add this line at the end of .bashrc or .zshrc
source /etc/bash_completion.d/git-prompt
On Github in the Git project, They provide a bash file to autocomplete git commands.
You should download it to home directory and you should force bash to run it. It is simply two steps and perfectly explained(step by step) in the following blog post.
code-worrier blog: autocomplete-git/
I have tested it on mac, it should work on other systems too. You can apply same approach to other operating systems.
Just put below in the .bashrc and relaunch the terminal. Navigate to Git repo to see the path in the prompt.
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] # \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '

Homebrew’s `git` not using completion

When using OSX’s git, after I modify a file I can simply do git commit <tab>, and that’ll auto complete the file’s name to the one that was modified. However, if I install a newer version of git from homebrew and I use it, that feature no longer works (meaning I press <tab> and it just “asks” me what file I want to do it on, even including the ones that have no changes).
Can anyone shed some light as to why, and how to solve that? I’d prefer using homebrew’s git, since it’s more up-to-date.
My shell is zsh, and Neither installing bash-completion or zsh-completions worked (even after following homebrew’s post-install instructions).
Also, after installing git with homebrew it says
Bash completion has been installed to: /usr/local/etc/bash_completion.d
zsh completion has been installed to: /usr/local/share/zsh/site-functions
So shouldn’t I be able to use one of those?
You're looking for:
brew install git bash-completion
As warpc's comment states, you'll need to add the following to your ~/.bash_profile to get homebrew's bash-completion working:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
The above is mentioned in the caveats when you install the bash-completion formula.
Note: if you are using Bash v4 or later (via brew install bash) then you're going to want to use brew install bash-completion#2, to enable tab completion add the following to ~/.bash_profile as described in the caveats:
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
The additional export is necessary for git, docker, youtube-dl, and other completions which may be included in the $(brew --prefix)/etc/bash_completion.d/ directory.
This get's git tab completion working on OSX without having to restart your terminal:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bash_profile
source ~/.bash_profile
EDIT: this doesn't work in Catalina's default zsh shell. I changed the default shell back to bash and it works again. https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/
In case anyone else makes my dumb mistake, try brew install git. I was using the git that comes with Xcode and didn't realize that I had never installed Homebrew's git to get the autocompletions.
for some reason I was missing the file at $(brew --prefix)/etc/bash_completion so #Graham Perks' correct answer didn't work for me
It ended up the fix in my case was:
brew unlink bash-completion
brew link bash-completion
I solved the problem by figuring out that $(brew --prefix)/etc/bash_completion returned Permission denied when executed. So after a simple:
chmod +x $(brew --prefix)/etc/bash_completion
Everything is now working fine. I'm wondering why Homebrew doesn't make the bash_completion file executable on installation, though.
For bash on macOS Catalina (3/30 update: Big Sur too), if you want to also use Bash 5 from homebrew, you need to make sure that your login shell is set to homebrew's bash, and not the default.
To check if you need to do this, run echo ${BASH_VERSION}. If you see a version starting with 3, you are not using Brew's bash for your login shell.
To change this,
Open System Preferences->Users and Groups.
Right click your user and select "Advanced Options". You may need to unlock this with your password by clicking the lock in the bottom left.
Set the login shell field to the location of your brew's bash, which you can usually find by running which bash in a terminal after you install brew's bash. Mine was /usr/local/bin/bash.
Restart your terminal, and follow the instructions in this excellent answer
Found a working solution. It's very recent (authored 16 hours ago, and committed 2 hours ago), and it comes directly from homebrew.
brew install git --without-completions
Just tried it, and it finally works as intended.
I had the same issue and even found this post this morning. I fixed the issue by updating brew with brew update and then reinstalling git with brew reinstall git.
I was then notified of another file that is blocking the homebrew linking process, in my case it was /usr/local/share/zsh/site-functions/git-completion.bash. Removing the file and running brew link git solved the issue. Guessing it was just a bad recipe version we stumbled upon.
If you have $BASH_VERSION < 4.1, eg 3.2.57(1)-release then go ahead with:
brew install bash-completion
# In ~/.bash_profile :
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
However if you've brew install bash to get version 4.4.12(1)-release
you can use the better and more complete completions in:
brew install bash-completion#2
# In ~/.bash_profile:
[ -f "$(brew --prefix)/share/bash-completion/bash_completion" ] \
&& . "$(brew --prefix)/share/bash-completion/bash_completion"
Note that some packages (brew, docker, tmux) will still put some completions into $(brew --prefix)/etc/bash_completion.d/ so you might add:
for completion in "$(brew --prefix)/etc/bash_completion.d/"*
do
. $completion
done
Finally you should be able to add the git completion script if for some reason the way you installed git did not add it to either of those:
[[ -f $(brew --prefix)/etc/bash_completion.d/git \
|| -f $(brew --prefix)/share/bash-completion/completions/git ]] \
|| curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash \
-o $(brew --prefix)/etc/bash_completion.d/git
You can get and add it with the above.
Step 1: Download auto completion script:
cd ~
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
Step 2: Update .bash_profile and .bashrc
echo "source ~/git-completion.bash" >> .bash_profile
Via https://www.anintegratedworld.com/git-tab-autocomplete-on-osx-10-11-el-capitan/
If above does not work, try https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
In 2019, using Bash v5, you do not need to explicitly source the git bash completion script in your .bash_profile or .bashrc
Ensure you have the following two lines in your .bashrc
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
Download the git bash completion script (https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash) and save it to /usr/local/etc/bash_completion.d/ as git
That's it! Bash will automatically pick up the git completion file and enable completion.
Side Note: I recommend putting all these changes in .bashrc as this ensures that when you drop into an interactive shell (ie. from pipenv shell), completions will get loaded correctly as bash will source .bashrc and NOT .bash_profile.
For me , I had to put
source $(brew --prefix)/etc/bash_completion
into .bashrc (not .bash_profile) to get this to work.
".bash_profile is executed for login shells, while .bashrc is executed
for interactive non-login shells" -- from What is the difference between .bash_profile and .bashrc? It appears to me that MacOS Sierra doesn't execute .bash_profile when opening a new terminal window, only .bashrc.
I wouldn't put it in _bash_profile, because then I'd have to reboot/logout for updates to take effect.
This worked for me in Mojave (OSX 10.14.1):
brew install bash-completion
Then add the following line to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
It may have something to do with libedit being used instead of readline in Lion.
Try installing readline before git.
brew install readline
For those who already have brew bash-completion installed. I did not have the git completion script installed and could not find any tap for that.
So I added it manually:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o $(brew --prefix)/etc/bash_completion.d/git
Note that you have to rename the file and remove the extension for it to work.
If you do not have completion or git installed, install it in the accepted answer.
brew install git bash-completion
If you used homebrew to install git, then probably there is no need to install anything to support git completion.
"git-completion.bash" file is somewhere (mine was here: /usr/local/git/contrib/completion/git-completion.bash)
All you need to do is to find the file:
sudo find / -type f -name "git-completion.bash"
Then source its path in your .bash_profile.
For example I needed to add this line to my ~/.bash_profile:
source /usr/local/git/contrib/completion/git-completion.bash
Don't forget to source your ~/.bash_profile or reopen your terminal ;)
from:
how-enable-git-tab-completion-bash-mac-os-x
I know this is an old post, but you don't really need to install any additional packages.
Homebrew is informing you that there is a directory with all the stuff you need.
You can simply add the following line to your .bash_profile if you are using Bash:
source /usr/local/etc/bash_completion.d/git-completion.bash
If nothing works, it could be because you have an older version of bash and bash completion script is not getting sourced by the /usr/local/etc/profile.d/bash_completion.sh script. You can test this by adding a simple echo inside the conditionals in file /usr/local/etc/profile.d/bash_completion.sh:
10 if shopt -q progcomp && [ -r /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion ]; then
11 # Source completion code.
echo "doing bash completion or not"
12 . /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion
And open a new terminal. If you don't see the echo message, then the conditionals do not evaluate to true. In my case it was because the bash version was old, the default from mac 3.2.blah.
I did install a newer bash from brew, but i forgot to chsh and that caused me a lot of headache. bash --version would return 5.1.8 but the enabled shell was still the old one :) To test the enabled bash you can do
for n in {0..5}
do
echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}"
done
The fix was to sudo chsh -s /usr/local/bin/bash After which the completions worked.
After tearing my hair out over this one for ages, I discovered that when I had the hub command installed, the completions for the hub command were breaking the completions for git. I had to remove /usr/local/etc/bash_completion.d/hub.bash_completion.sh. This meant no completions for hub, but git completions now worked. I didn't debug why this was.
I had the following brew packages installed:
bash: 5.1.16
bash-completion#2: 2.11
git: 2.35.1
hub: 2.14.2
Enable Auto Completion of GIT commands on MAC-OS Mojave 10.14
I am a developer and use GIT from the command line all of the time. When I consider the development perspective, I used to execute a lot of commands using the command line for GIT operations. Most of the time it is very annoying that MAC OS doesn't have automatic support for the command completion which I partially support. as well as the command suggestions, which means what are the commands available for typed characters. So it is very troublesome to type very long command and mostly repetitive task as typo going wrong. :(
Tab completion would certainly be faster and easier. Unfortunately, the default installation of git on some Mac computers doesn't have tab completion enabled.
So that I was searching for a fix for the problem and there are several solutions found from the web search such as StackOverflow, GitHub as well as from the medium. Unfortunately, those solutions did not work for me and got frustrated with trying different solutions so many times.
I was searching deeply and trying out different solutions and fortunately, it is an easy fix. Below are the steps I have collected from several posts and finally it worked as expected. So I hope to share with others who have this problem like me.
f you go to the web search and you can find many solutions which mentioned the git completion bash file. Even GitHub guide as well. But I suggest you check first if the git-completion.bash file is already in your MAC computer with the git-core or something else which came from installation. you can use below command.
sudo find / -type f -name "git-completion.bash"
you will get below results. (may have some difference according to the content)
/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
/Users/Dilanka/git-completion.bash
/Users/Dilanka/.oh-my-zsh/plugins/gitfast/git-completion.bash
/Users/Dilanka/Downloads/git-completion.bash
I suggest you to pick which installed from git-core
If the git-completion.bash script doesn't exist on your machine, please retrieve it from the below provided above and save it to your local machine in a new file called git-completion.bash in the /usr/local/etc/bash_completion.d/ directory.
https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks
If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download it directly from the Git source code at
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
If the git-completion.bash script exists on your machine, but is not in the /usr/local/etc/bash_completion.d/ directory, you should create that directory and copy the file into it. Below command will do the job:
sudo mkdir /opt/local/etc/bash_completion.d
sudo cp /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash /usr/local/etc/bash_completion.d/git-completion.bash
After the completion of above. The git-completion.bash script should exist on your local machine in the/usr/local/etc/bash_completion.d/ directory.
Now you need to refresh your profile using below command. It will load your added bash file to the terminal context.
source ~/.bash_profile
Great!!! you have done it. Just start the terminal window and try it. Just type "git sta" it will show suggestions as below:
git sta
stage stash status
git chec<TAB> will show git checkout
see my GitHub post here:
https://github.com/DIL8654/Enable-Auto-Completion-of-GIT-commads-on-MAC-OS-Mojave
See my Medium post here:
https://medium.com/#dilanka85/enable-auto-completion-of-git-commands-on-mac-os-mojave-10-14

How to use correct ruby in vim ? How to modify $PATH in VIM?

I use plain Vim with ruby support on Lion (installed by gist). I am using ruby with rbenv so my path looks like /users/me/.rbenv/shims:.....
From within vim the path is
:!echo $PATH
> usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:....
Even I can create and modify an environment variable:
:let $PATH = "/bar:/foo"
:!echo $PATH
> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/foo:/bar
paths remains starting with /usr/bin.
So how can I access my ruby 1.9.3 in ~/.rbenv/shims instead the system ruby in /usr/bin ?
This is a known problem introduced by Apple in OS X 10.5 Leopard.
If you are using Bash or Zsh and are using non-interactive shells, you are affected.
Running sudo chmod ugo-x /usr/libexec/path_helper will fix you up, but you should take a look at the article to see why.
rvm also has this problem. If zsh is your default shell when it starts /etc/zshenv gets executed.
This executes /usr/libexec/path_helper. That sets up the path based on the contents /etc/paths and /etc/paths.d/.
The faq for rvm mentions moving /etc/zshenv to /zsh/zshrc. I did this and it removed the /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin from the start of my path in macvim.
I did'n t set the shell option in .vimrc, so that it was automatically set to /bin/zsh.
Then I found out that I hab a dublicate initialisation of rbenv: in my .zshrc. I removed the initialisation end $PATH extensioin in .zshrc because that was already handled by the oh-my-zsh rbenv plugin.
Even after that cleanup, the $PATH mangeling still happening so :!echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/games
Setting :set shell=/bin/bash was what helped me, as i can live with bash in my vim: :!echo $PATH
/Users/fb/.rbenv/shims:/Users/fb/.rbenv/bin:/Users/fb/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/Users/fb/Dropbox/local/bash
In your ~/.bashrc (or whatever shell you're using) file, add the following line:
PATH=/home/me/.rbenv/shims:${PATH}
and then run source ~/.bashrc (or .zshrc or whatever shell you're using!)
This can be fixed by just adding
PATH=/home/me/.rbenv/shims:${PATH}
to
/etc/zshenv
I don't use mac or zsh (I am on linux), however I ran into this problem when I ran gvim from the MATE Menu.
I solved it by adding this to my .vimrc:
if $PATH !~ "\.rbenv"
let $PATH="/home/username/.rbenv/shims:/home/username/.rbenv/bin:" . $PATH
endif
This avoids setting it if you run vim from a terminal, otherwise the rbenv paths would be included twice.
I tried setting the application to run via a terminal, but that didn't help.
yes on OS X it's the bash_profile that gets sourced when opening a new console window whereas on Linux it's your bashrc

Update built-in vim on Mac OS X

I know this might be more appropriate at Ask Different, but as I tried adding tags there, there was no vim tag, only macvim. So I figured I might get a better audience here.
In the Terminal, I do the following
$ vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jan 31 2010 13:33:49)
When I browse to http://www.vim.org, I see a news item
Vim 7.3 released!
How do I update my built-in vim? I would very much like to do it cleanly (i.e. no duplicate installations, or any additional downloads, no macports, etc.)
I considered using Mercurial (as I already use it for other things), as per the instructions here.
$ hg clone https://vim.googlecode.com.hg/ vim
$ cd vim/src
$ make
But I think that would make a duplicate installation. Despite my "clean" requirement as mentioned above, "unclean" solutions are also welcome, since maybe there really is no other way.
If I understand things correctly, you want to install over your existing Vim, for better or worse :-) This is a bad idea and it is not the "clean" way to do it. Why? Well, OS X expects that nothing will ever change in /usr/bin unbeknownst to it, so any time you overwrite stuff in there you risk breaking some intricate interdependency. And, Let's say you do break something -- there's no way to "undo" that damage. You will be sad and alone. You may have to reinstall OS X.
Part 1: A better idea
The "clean" way is to install in a separate place, and make the new binary higher priority in the $PATH. Here is how I recommend doing that:
$ # Create the directories you need
$ sudo mkdir -p /opt/local/bin
$ # Download, compile, and install the latest Vim
$ cd ~
$ hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
$
$ cd vim
$ ./configure --prefix=/opt/local
$ make
$ sudo make install
$ # Add the binary to your path, ahead of /usr/bin
$ echo 'PATH=/opt/local/bin:$PATH' >> ~/.bash_profile
$ # Reload bash_profile so the changes take effect in this window
$ source ~/.bash_profile
Voila! Now when we use vim we will be using the new one. But, to get back to our old configuration in the event of huge f*ckups, we can just delete the /opt directory.
$ which vim
/opt/local/bin/vim
$ vim --version | head -n 2
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Aug 27 2011 20:55:46)
MacOS X (unix) version
See how clean this is.
I recommend not to install in /usr/local/bin when you want to override binaries in /usr/bin, because by default OS X puts /usr/bin higher priority in $PATH than /usr/local/bin, and screwing with that opens its own can of worms.... So, that's what you SHOULD do.
Part 2: The "correct" answer (but a bad idea)
Assuming you're set on doing that, you are definitely on track. To install on top of your current installation, you need to set the "prefix" directory. That's done like this:
hg clone https://bitbucket.org/vim-mirror/vim or git clone https://github.com/vim/vim.git
cd vim
./configure --prefix=/usr
make
sudo make install
You can pass "configure" a few other options too, if you want. Do "./configure --help" to see them. I hope you've got a backup before you do it, though, in case something goes wrong....
Don't overwrite the built-in Vim.
Instead, install it from source in a different location or via Homebrew or MacPorts in their default location then add this line to your .bashrc or .profile:
alias vim='/path/to/your/own/vim'
and/or change your $PATH so that it looks into its location before the default location.
The best thing to do, in my opinion, is to simply download the latest MacVim which comes with a very complete vim executable and use it in Terminal.app like so.
alias vim='/Applications/MacVim.app/Contents/MacOS/Vim' # or something like that, YMMV
Like Eric, I used homebrew, but I used the default recipe. So:
brew install mercurial
brew install vim
And after restarting the terminal homebrew's vim should be the default. If not, you should update your $PATH so that /opt/homebrew/bin is before /usr/bin. E.g. add the following to your .profile:
export PATH=/opt/homebrew/bin:$PATH
Note: Previous versions of Homebrew did install to /usr/local, so in that case you have to use /usr/local/bin instead of /opt/homebrew/bin.
A note to romainl's answer: aliases don't work together with sudo because only the first word is checked on aliases. To change this add another alias to your .profile / .bashrc:
alias sudo='sudo '
With this change sudo vim will behave as expected!
On Yosemite, install vim using brew and the override-system-vi option. This will automatically install vim with the features of the 'huge' vim install.
brew install vim --with-override-system-vi
The output of this command will show you where brew installed vim. In that folder, go down into /bin/vim to actually run vim. This is your command to run vim from any folder:
/usr/local/Cellar/vim/7.4.873/bin/vim
Then alias this command by adding the following line in your .bashrc:
alias vim="/usr/local/Cellar/vim/7.4.873/bin/vim"
EDIT: Brew flag --override-system-vi has been deprecated. Changed for --with-override-system-vi. Source: https://github.com/Shougo/neocomplete.vim/issues/401
brew install vim --override-system-vi
This blog post was helpful for me. I used the "Homebrew built Vim" solution, which in my case saved the new version in /usr/local/bin. At this point, the post suggested hiding the system vim, which didn't work for me, so I used an alias instead.
$ brew install vim
$ alias vim='/path/to/new/vim
$ which vim
vim: aliased to /path/to/new/vim
I just installed vim by:
brew install vim
now the new vim is accessed by vim and the old vim (built-in vim) by vi

Resources