Environment: debian9+vim7.4.
cat .bashrc add(){ echo $(expr $1 + $2) }
Now edit a file in vim
add 1 5
The problem is your function is limited to an interactive shell to execute it you have to do like this
:!bash -ic "add 1 2"