title: Is it wrong to have two statements inside an if on vimscript?
body: <p>I recently decided to revamp my <code>.vimrc</code>.</p>
  
  <p>As per instructions <a href="https://github.com/Valloric/YouCompleteMe/issues/420#issuecomment-55940039" rel="nofollow">here</a>, I added a small snippet in a file called <code>ultisnips_tab_hack.vim</code>, which is sourced in my <code>.vimrc</code>.</p>
  
  <p>The last line of that snippet is this:</p>
  
  <pre><code>inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;"
  </code></pre>
  
  <p>Which from what I could tell was mapping <kbd>Enter</kbd> to an expression that would test if the pop-up menu was visible. If it was, the inserted text would be decided by the <code>ExpandSnippetOrCarriageReturn()</code> function that is defined in the snippet. Else a simple carriage return would be inserted.</p>
  
  <p>This snippet is supposed to make YouCompleteMe and Ultisnips behave, and, as per <a href="https://github.com/Valloric/YouCompleteMe/issues/420#issuecomment-152884272" rel="nofollow">this other comment</a>, the last line should be modified to the following to make it also behave with <code>vim-endwise</code>. </p>
  
  <pre><code>let g:endwise_no_mappings = 1
  inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;\&lt;C-R&gt;=EndwiseDiscretionary()\&lt;CR&gt;"
  </code></pre>
  
  <p>Which is the same except that if the pop-up menu is not visible, it will also call the <code>vim-endwise</code> function to decide if something else should be inserted. And also, the endwise mapping is disabled, so that it won't conflict with our custom mapping.</p>
  
  <p>So, I was trying to make a solution that would work whether <code>vim-endwise</code> was loaded or not (because I wanted to load it only on ruby files). And what I tried was:</p>
  
  <pre><code>if exists("*EndwiseDiscretionary")
    let g:endwise_no_mappings = 1
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;\&lt;C-R&gt;=EndwiseDiscretionary()\&lt;CR&gt;"
  else
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;"
  endif
  </code></pre>
  
  <p>To my surprise, that gave me the following weird error on vim when I pressed <kbd>Enter</kbd> (and <code>vim-endwise</code> was loaded).</p>
  
  <pre><code>E15: Invalid Expression: ExpandSnippetOrCarriageReturn()\
  </code></pre>
  
  <p>And also, the following text was inserted: <code>pumvisible() ? "</code> instead of a carriage return.</p>
  
  <p>To my even-more-surprise, though, the following caused no errors at all, whether <code>vim-endwise</code> was loaded or not.</p>
  
  <pre><code>let g:endwise_no_mappings = 1
  if exists("*EndwiseDiscretionary")
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;\&lt;C-R&gt;=EndwiseDiscretionary()\&lt;CR&gt;"
  else
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;"
  endif
  </code></pre>
  
  <p>I've been bitten by some weird vimscript stuff before, so I'm now wondering if two statements inside an if causes this kind of problems and I'm supposed to always extract them to a function.</p>
  
  <p>Or maybe I need a special separator that I don't know of, or something like that. Maybe it's a problem with a variable assignment right above a  mapping?</p>
  
  <p>Can any vim guru please elucidate me?</p>
  
  <h2>TL;DR</h2>
  
  <p>Causes weird <code>E15: Invalid Expression: ExpandSnippetOrCarriageReturn()\</code> error when I press <kbd>Enter</kbd> on insert mode:</p>
  
  <pre><code>if exists("*EndwiseDiscretionary")
    let g:endwise_no_mappings = 1
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;\&lt;C-R&gt;=EndwiseDiscretionary()\&lt;CR&gt;"
  else
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;"
  endif
  </code></pre>
  
  <p>Work as intended:</p>
  
  <pre><code>let g:endwise_no_mappings = 1
  if exists("*EndwiseDiscretionary")
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;\&lt;C-R&gt;=EndwiseDiscretionary()\&lt;CR&gt;"
  else
    inoremap &lt;expr&gt; &lt;CR&gt; pumvisible() ? "\&lt;C-R&gt;=ExpandSnippetOrCarriageReturn()\&lt;CR&gt;" : "\&lt;CR&gt;"
  endif
  </code></pre>