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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With