VimL: Checking if function exists

greduan picture greduan · Dec 4, 2012 · Viewed 9.8k times · Source

right now I'm cleaning up my .vimrc file to make sure it's compatible on most systems.

In my statusline I use a function that another plugin sets, the GitBranchInfoString() function introduced by this plugin.

What I wanna do is check if this function is set, and only then add it to the statusline. It would be in it's own line so I just need to check for it.

What would be the simplest way to accomplish this?

Thanks for all your help!

EDIT:

I have the following:

if exists('*GitBranchInfoString')
    let &stl.='%{GitBranchInfoString()}'
endif

Answer

ZyX picture ZyX · Dec 4, 2012

Use

if exists("*GitBranchInfoString")
    " do stuff here
endif