title: How to vim script to execute commands in function
body: <p>I write new code in my .vimrc (I am very new to vim scripting)</p>
  <h3>what I want is</h3>
  <p>Open definition page for word under the cursor to the right side of splited window</p>
  <p>so left window is just for index, and right one is for preview (like below picture)</p>
  <h3>My function intention is</h3>
  <ol>
  <li>first time open split as vertical window, then do K(in normal mode)</li>
  <li>and after first time I close right window and do the same process</li>
  </ol>
  <p>but when I invoked function, I got an error <code>Invalid argument</code></p>
  <pre class="lang-sh prettyprint-override"><code>nnoremap &lt;Leader&gt;&lt;CR&gt; :call Goto_definition() &lt;CR&gt;
  
  let g:first_open=0
  function! Goto_definition() 
      if g:first_open
          :vs &lt;bar&gt; :wincmd l &lt;CR&gt; // 1. vertical split and go to right window
          :exe 'normal K'          // 2. then press shortcut K (in normal mode)
          let g:first_open=0       // 3. set variable
      else 
          :wincmd l&lt;bar&gt; :q&lt;bar&gt;  // 4 .close right window first (because it's not a first time)
          :vs &lt;bar&gt; :wincmd l &lt;CR&gt; // repeat step 1~3 
          :exe 'normal K'
      endif
  endfunction
  
  </code></pre>
  <p>What is the wrong code in my function??</p>
  <p><a href="https://i.stack.imgur.com/hCiDu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hCiDu.jpg" alt="enter image description here" /></a></p>