I'm now using

silent! let l:status = system(l:command . ' > /dev/null')

if match(l:status, '\cunknown') != -1 || match(l:status, '\cnot') != -1
    echo 'command not found'
    return 0`enter code here`

i know it's not complete but is there any better way to check?


i'm now using

silent! let l:status = system('which espeak')

if l:status !~ '\w\+'
    echo 'command not found'
    return 0


changed from which to command https://unix.stackexchange.com/questions/85249/why-not-use-which-what-to-use-then

  • 1
    In bash, my standard is command -v <command name> >/dev/null and check the exit code.
    – D. Ben Knoble
    Jul 20, 2018 at 2:49
  • @D.BenKnoble is which better? i'm using fish and i just fund command -v in bash is command -s in fish, but which is all the same
    – tga
    Jul 20, 2018 at 3:18
  • which only works on external utilities, so not shell builtins.
    – D. Ben Knoble
    Jul 20, 2018 at 3:34
  • 1
    @wengwengweng unix.stackexchange.com/questions/85249/…
    – muru
    Jul 20, 2018 at 8:17
  • @wengwengweng if the solution you found is satisfying you can answer your own question (instead of editing it), that will make it more useful and easier to read for future users with the same question.
    – statox
    Jul 20, 2018 at 11:21

2 Answers 2


Incidentally vim has a special function just for this: executable().


thanks for the comments above, i'm using this code right now:

silent! let l:status = system('command -v ' . l:cmd)

if l:status !~ '\w\+'
    echo 'command not found'
    return -1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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