My .vimrc uses pathogen by doing

execute pathogen#infect()

However if I set up a new computer and haven't installed pathogen with

mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim

Then every time I go to edit a file I get a message about pathogen not working (and then I can edit the file).

I'd like my .vimrc call to execute pathogen#infect be dependent on ~/.vim/autoload actually existing.

In shell scripting I would do something like

if test -f ~/.vim/autoload
  execute pathogen#infect()

but of course that gives undefined method test. .vimrc uses a different syntax like having " instead of # for comments and for a conditional I don't know what the right format is.

What format I would use for a .vimrc file?

2 Answers 2


filereadable() or isdirectory() would be better choices than findfile() -- the latter one searches in a set of directories. BTW, findfile() returns nothing (an empty string) on my system for ~/.vim

However, isdirectory() cannot process ~/, but fnamemodify() comes to the rescue.

if isdirectory(fnamemodify('~/.vim/autoload', ':p'))
    execute pathogen#infect()

isdirectory($HOME.'/.vim/autoload') would have worked as well.


This worked:

if findfile("~/.vim/autoload")
  execute pathogen#infect()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .