VimL: function check

right now I'm cleaning my .vimrc file to make sure it is compatible with most systems.

In my status bar, I use a function that another plugin GitBranchInfoString() , GitBranchInfoString() , introduced by this plugin .

What I want to do is check if this function is installed, and only then add it to the status bar. That would be on its own line, so I just need to check it out.

What would be the easiest way to accomplish this?

Thanks for your help!

EDIT:

I have the following:

 if exists('*GitBranchInfoString') let &stl.='%{GitBranchInfoString()}' endif 
+16
vim vim plugin
Dec 04 '12 at 19:23
source share
3 answers

Using

 if exists("*GitBranchInfoString") " do stuff here endif 
+23
Dec 04 '12 at 19:25
source share

The currently selected answer does not work for me (using Vim 7.4 / Ubuntu). I believe that since:

.vimrc loads before loading any plugins

As @ZyX noted in the comment.

My preferred method is to simply check for the presence of the plugin file . I find this cleaner than writing a single function to an external file.

 if !empty(glob("path/to/plugin.vim")) echo "File exists." endif 
+6
May 25 '15 at 18:59
source share

Alternatively, you can also use regex to decide if your plugin is in your runtimepath :

 if &rtp =~ 'plugin-name' ... endif 

This has the advantage that it works with plugins that have only vimscript code in the autoload directory, which, in turn, cannot be detected when .vimrc is initially parsed, since autoload fragments are loaded during the call function.

0
Jan 10 '18 at 0:11
source share



All Articles