Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if exists(":command") fails on startup, using Pathogen

Tags:

vim

I'm using exists() to check if plugins are installed in Vim (I mapped ; to :):

if exists(":NERDTree")
    map <F4> ;NERDTreeToggle<CR>
endif

The mapping doesn't work unless I source the .vimrc file manually. I'm using Pathogen to load my plugins on startup, I imagine that has something to do with it?

My complete .vimrc file: https://github.com/ElbertF/dotfiles/blob/master/.vimrc

like image 722
Elbert Alias Avatar asked Feb 15 '11 22:02

Elbert Alias


1 Answers

Your call to exists() doesn't work because plugins are only loaded after vim has finished processing your .vimrc - see :help startup. Also, pathogen doesn't actually load your plugins, it merely adds their containing folders to the runtimepath option so they will be loaded after your .vimrc.

You could create a VimEnter autocmd to set up your mapping after vim has finished loading:

autocmd VimEnter * if exists(":NERDTree") | exe "map <F4> ;NERDTreeToggle\<CR>" | endif
like image 76
too much php Avatar answered Sep 21 '22 01:09

too much php