5

Say, I defined a command in my ~/.bash_profile, (MacOS Sierra, Macbook Air, if it's relevant)

function sayHello(){
   echo Hello world!
}

and while using vim, intend to call

:! sayHello

It does not recognize, and tells me

/bin/bash: sayHello: command not found
shell returned 127

The actual situation is that I want compile something, so it would be handy to use external command. If not, then fine, I can open up another terminal, cd-ed on the same directory.

1 Answer 1

5

External commands are not executed in an interactive shell so your .bash_profile is not read. To make your custom command available you must turn it into an actual shell script, put it in your $PATH, and make it executable:

#!/usr/bin/env bash

echo "Hello world!"

But there's a much better way to "compile something": :help :make.

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.