Environment: debian9+vim7.4.
cat .bashrc
add(){
echo $(expr $1 + $2)
}
Now edit a file in vim
add 1 5
Run it in command mode :w !bash
,an error occur.
bash: line 1: add: command not found
shell returned 127
1.add set shellcmdflag=-ic
in both /etc/vim/vimrc and .bashrc and .vimrc .
2.reboot
3.vim test.sh
enter into command mode
:verbose set shellcmdflag
shellcmdflag=-ic
Last set from ~/.vimrc
4.input two lines in test.sh
ls
add 5 6
:w !bash
a1.sh test.py
bash: line 2: add: command not found
shell returned 127
How to make both two lines executed?
:execute '! source ~/.bashrc; source '.expand('%:p')
can make both commands: ls
and add
run.
After rebooting,
1.add function can't be called from sh test.sh
?
sh test.sh
test.sh #it means that ls command executed
test.sh: 2: test.sh: add: not found #it means that add function can't be called from /etc/vim/vimrc or .bashrc or .vimrc.
2.add function can't be called from vim !bash %
?
test.sh #it means that ls command executed
test.sh: line 2: add: command not found #it means that add function can't be called from /etc/vim/vimrc or .bashrc or .vimrc.
[4]+ Stopped vim test.sh