Shaun Luttin
Shaun Luttin

Reputation: 141622

Unknown function error when opening Vim with 'git commit' command but not with 'vim' command

When I open Vim from the command line with vim, my _vimrc file runs without an error. When git commit opens vim as its editor, the following error occurs:

C:\dev\settings>git commit                                                                   
hint: Waiting for your editor to close the file... 
Error detected while processing /c/Users/me/_vimrc:
line    1:                                                                 
E117: Unknown function: pathogen#infect                                    
E15: Invalid expression: pathogen#infect()        
Press ENTER or type command to continue

Why does pathogen#infect() cause an error when git opens vim? How do we fix this?

Upvotes: 1

Views: 568

Answers (3)

Shaun Luttin
Shaun Luttin

Reputation: 141622

Based on VonC's suggestion, my initial fix was to have both ~/.vim and ~/vimfiles.

PS> Copy-Item ~\vimfiles\ ~\.vim -Recurse

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172648

Git ships with its own copy of Vim, and that one is built with Unix-style paths, so it looks for your plugins (like Pathogen) in ~/.vim/ instead of ~/vimfiles.

Duplicating your configuration is one way to solve it, but then you'll have to maintain both in parallel. I think a better approach is to make all Vim versions use the same configuration, by adapting the 'runtimepath' inside your ~/.vimrc. The following fragment (to be put at the top of your ~/.vimrc) will make Windows use the Unix-style paths:

" On Windows, also use ~/.vim instead of ~/vimfiles; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
    let &runtimepath = substitute(&runtimepath, '\C\V' . escape($HOME.'/vimfiles', '\'), escape($HOME.'/.vim', '\&'), 'g')
    if exists('&packpath')
        let &packpath = &runtimepath
    endif
endif

Upvotes: 2

VonC
VonC

Reputation: 1326782

As illustrated in issue 687, that means vim, as executed in a git bash context, does not recognize pathogen.

Upvotes: 1

Related Questions