chys
chys

Reputation: 1652

Check whether pathogen is installed in vimrc

I would like to check in .vimrc whether pathogen is present, and call pathogen#infect if it is.

This obviously works:

call pathogen#infect()

So I'm confident pathogen is properly installed.

But this does not load pathogen:

if exists("*pathogen#infect")
    call pathogen#infect()
endif

Neither does this:

if exists("g:loaded_pathogen")
    call pathogen#infect()
endif

What am I missing?

Upvotes: 7

Views: 2070

Answers (2)

ObiWahn
ObiWahn

Reputation: 111

This is my solution for the problem:)

if filereadable(expand("~/.vim/autoload/pathogen.vim"))
    runtime! autoload/pathogen.vim
    if exists("g:loaded_pathogen")
       execute pathogen#infect()
    endif
endif

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172570

Your check doesn't work because of the autoload mechanism. You could force the autoload by explicitly sourcing it:

runtime! autoload/pathogen.vim
if exists("*pathogen#infect")
    call pathogen#infect()
endif

But in the end, you probably just want to avoid errors from your .vimrc when Pathogen isn't installed. For that, just silence any resulting errors with :silent!:

silent! call pathogen#infect()

The only downside is that any Pathogen plugin errors would be suppressed.

Upvotes: 12

Related Questions