There's a lot of code in dirdiff, but it's a plugin with very specific use cases: you don't use it every time you start up vim. Instead of processing all of that vimscript every time, just do it when you start vim.
:h autoload
explains more about it, but now that dirdiff depends on ZFVimJob it seems like there's even more code to load on startup and makes it a good candidate for autoload.
A shortcut to this conversion is to autoload just the commands:
Move plugin/*.vim to autoload/zfdirdiff/, rename some functions, and move the :command
lines back to plugin/zfdirdiff.vim. Could also make some wrapper functions in plugin/zfdirdiff.vim for backwards compatibility.
Renames would look like:
- ZFDirDiffAPI_init -> zfdirdiff#api#init
- ZFDirDiffMark -> zfdirdiff#mark#Mark
- ZFDirDiffUnmark -> zfdirdiff#mark#Unmark
Since this only uses vim's autoload naming for a few functions, you'd also want a load function in each autoload file and call all of them at the top of autoload/zfdirdiff/api.vim so they'll all load:
function! zfdirdiff#ui#load() abort
endf
(Autoload will use the function name to discover the file, load it, and call the function.)
zfdirdiff has a ton of global functions that people could be using. Putting one of those load dummy functions in api.vim would allow people to call zfdirdiff#api#load()
in their vimrc to have access to those global functions, but also lose the benefits of autoload.
Or you could autoload all the functions in api.vim. Or all the functions you want exposed (then you wouldn't need those load dummy functions).
Something like these two substitutes might get you most of the way there for a full conversion since you've already namespaced functions with underscores:
%s/\v\s\zsZFDirDiff_(\k+)_(\k+)\(/zfdirdiff#\1#\2(/g
%s/\v\s\zsZFDirDiff_(\k*)\(/zfdirdiff#\1(/g
But I can see one problem you'd run into are functions like ZFDirDiff_excludeCheck_fallback()
because zfdirdiff#excludeCheck#fallback()
vim requires an autoload function with that name to be in autoload/zfdirdiff/excludeCheck.vim
.
I'm not sure what to do with all the configuration. Also move it to autoload?
zfdirdiff is a big plugin and has a bunch of dependencies, so converting to autoload is a big task. If you don't want to write your plugins with autoload, I get it. Thanks for the great plugin regardless!