1

I have a script that checks for a certain condition (it checks if pip dependencies are installed). If they are installed and everything is ok, I want to import a bunch of python functions from my plugin so they are available to the user. However, if it's not available, I just want to print a message and skip the rest of the script.

Now, I was thinking of wrapping the whole operation in a function with abort like this:

function! checkPipDeps() abort
    ...
    if dependencyMissing
        throw "Your dependency is missing"
    endif

    ...
    python3 import dependency
endfunction

checkPipDeps()

but this does look clunky. I was wondering if there is a better solution where I can just return a dud value or something, that would allow me to skip the rest of the script but not mess up the initial loading process.

3

Use :finish:

if hasNoDependency()
    finish
endif

" all dependencies are met, good to go
" ...

I use it for minpac plugin manager (not only here of course):

if !exists('*minpac#init') | finish | endif

call minpac#init()
call minpac#add('k-takata/minpac', {'type': 'opt'})

"" My plugins
call minpac#add('git@github.com:habamax/vim-asciidoctor.git', {'rev': 'master'})
call minpac#add('git@github.com:habamax/vim-evalvim.git', {'rev': 'master'})
...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.