title: How to make the vim call function in .bashrc?
body: <p>Environment: debian9+vim7.4.    </p>
  
  <pre><code>   cat .bashrc
     add(){
          echo $(expr $1 + $2)
      }
  </code></pre>
  
  <p>Now edit a file in vim</p>
  
  <pre><code>add 1 5 
  </code></pre>
  
  <p>Run it in command mode <code>:w !bash</code>,an error occur.</p>
  
  <pre><code>bash: line 1: add: command not found    
  shell returned 127
  </code></pre>
  
  <p>1.add <code>set shellcmdflag=-ic</code>  in both /etc/vim/vimrc and .bashrc  and .vimrc .<br>
  2.reboot<br>
  3.vim test.sh<br>
  enter into command mode<br>
  :verbose set shellcmdflag   </p>
  
  <pre><code>  shellcmdflag=-ic
          Last set from ~/.vimrc
  </code></pre>
  
  <p>4.input two lines in test.sh</p>
  
  <pre><code>ls
  add  5  6
  
  :w !bash     
  a1.sh       test.py    
  bash: line 2: add: command not found    
  shell returned 127    
  </code></pre>
  
  <p>How to make both two lines executed? 
  <a href="https://i.stack.imgur.com/qxwQS.png" rel="noreferrer"><img src="https://i.stack.imgur.com/qxwQS.png" alt="enter image description here"></a><br>
  <a href="https://i.stack.imgur.com/5rQcV.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5rQcV.png" alt="enter image description here"></a></p>
  
  <p><code>:execute '! source ~/.bashrc; source '.expand('%:p')</code> can make both commands: <code>ls</code> and <code>add</code> run.     </p>
  
  <p>After rebooting,<br>
  1.add function can't be called from <code>sh test.sh</code>?   </p>
  
  <pre><code>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.
  </code></pre>
  
  <p>2.add function can't be called from vim <code>!bash %</code>?</p>
  
  <p><a href="https://i.stack.imgur.com/yxdRW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yxdRW.png" alt="enter image description here"></a></p>
  
  <pre><code>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
  </code></pre>