vim not loading _vimrc file when launched from git bash

13

6

I have downloaded and installed git for windows (msysgit) and frequently used the included git bash. Whenever I run vim from git bash my _vimrc file is not loaded because there is syntax highlighting or anything. When I run the same command to start vim form with in windows command line (cmd) instead of git bash it works as described in my _vimrc file. The only customization I have done to git bash is to add the following bash_profile to C:\Program Files (x86)\Git\etc

alias up='cd ..'
alias ls='ls --color'
alias la='ls -a'
alias vimconfig='vim /c/Program\ Files/Vim/_vimrc'
alias gvimconfig='vim /c/Program\ Files/Vim/_gvimrc'
alias bashconfig='vim /c/Program\ Files/Git/etc/bash_profile'
LS_COLORS='di=36:fi=37:ln=31:pi=5:so=5:bd=5:cd=5:or=31:mi=0:ex=35:*.rpm=90'
export LS_COLORS

Does anyone know why it loads my _vimrc file correctly when vim is launched from cmd and incorrectly when launched from git bash?

Ben

Posted 2011-05-07T04:24:34.270

Reputation: 321

Answers

14

msysgit comes with its own version of vim.

You can verify this by running

type vim

inside your git bash prompt.

I think it will tell you that vim = /bin/vim, not /c/Program Files/Vim/Vim.exe.

Then run

vim --version | grep vimrc

to see which config files it looks for.

On my system, it says

$ vim --version | grep vimrc
   system vimrc file: "$VIM\vimrc"
     user vimrc file: "$HOME\_vimrc"
 2nd user vimrc file: "$VIM\_vimrc"

$VIM points to C:\Program Files\Git\share\vim and $HOME points to c:\Users\USERNAME.

I guess your best option is to run your Windows-based version of vim, e.g.

alias vim='/c/Program Files/Vim/Vim.exe'

or similar.

Or you could move the msysgit version of vim aside, e.g.

mv /bin/vim /bin/vim.disabled

Mikel

Posted 2011-05-07T04:24:34.270

Reputation: 7 890

Thanks, it works perfectly. I followed the last command in windows 8.1 – Ibn Saeed – 2015-03-23T09:29:22.550

Did you mean "msysgit comes with its own version of vim."? – Heptite – 2011-05-07T17:39:07.467

2Note that you might have to run git bash as Administrator to do that last line. – Kristo – 2012-06-11T02:58:03.173

2

/bin/vim is just a redirect script, you can modify it and set the path to whatever you want.

Edit C:\Program Files (x86)\Git\bin\vim as an administrator.

Change this:

#!/bin/sh

exec /share/vim/vim74/vim "$@"

To this (or whatever your path is):

#!/bin/sh

exec "/c/Program Files (x86)/Vim/vim74/gvim.exe" "$@"

Dan

Posted 2011-05-07T04:24:34.270

Reputation: 612

1

in vim, type :scriptnames.

:scr[iptnames] -- List all sourced script names, in the order they were first sourced. The number is used for the script ID.

qeatzy

Posted 2011-05-07T04:24:34.270

Reputation: 227

2Please read the question again carefully. Your answer does not answer the original question. – DavidPostill – 2016-06-12T08:24:39.763

@DavidPostill, IMHO, it's not off-topic, since the problem is his customized script is not sourced all, or be overriden by other scripts. My answer say how to know which scripts are sourced and in what order thy are sourced. Also note that it's a quite old question, my point is not only to answer the original question but to generalize well. – qeatzy – 2016-06-13T11:16:27.457

I didn't say it was off-topic, I said it didn't answer the question. – DavidPostill – 2016-06-13T11:19:09.633

I did answer the question. By :scr[iptname], you know your script is ever loaded or not. If loaded, what is the candidate that override it. Please read the question again. -- there could be two vim installed, and their startup process may be different. – qeatzy – 2016-06-13T11:27:58.617