title: The reason why multi line visual selection line doesn't work
body: <p>I've written two simple functions as well as defined a mapping to use them. The idea is to do a <code>grep</code> type search (with <code>ag</code>) for current visual selection. </p>
  
  <p>Here is the code:</p>
  
  <pre><code>function! s:VisualAg()
    let temp = @"
    normal! gvy
    try
      call &lt;SID&gt;PrjAck('"'.@".'"', g:proj_root)
    catch
      let @" = temp
      echoerr v:exception
    endtry
  endfunction
  
  function! s:PrjAck(pattern, ...)
    " -S - smart case
    " -U - ignore VCS ignore files
    " -Q - Don't parse PATTERN as a regular expression
    " -G - PATTERN Limit search to filenames matching PATTERN
    let cmd = ":Ack -S -U -Q -G \"\\.(cpp\|h\|td)$\" ".a:pattern
    for parameter in a:000
      let cmd .= " ".parameter
    endfor
    execute cmd
  
  xnoremap &lt;leader&gt;gw :call &lt;SID&gt;VisualAg()&lt;cr&gt;
  </code></pre>
  
  <p>The mapping seems to work for a selection done within a line. However when I do a multi line selection it doesn't work.</p>
  
  <p>Here is what I get when I run this code on a multi line selection
  <a href="https://i.stack.imgur.com/XSRNA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XSRNA.png" alt="enter image description here"></a></p>
  
  <p>I tried to debug it and replaced the <code>execute cmd</code> line in <code>s:PrjAck(pattern, ...)</code> with <code>echo cmd</code>. Here is the output that I got
  <a href="https://i.stack.imgur.com/zSUf1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zSUf1.png" alt="enter image description here"></a></p>
  
  <p>Frankly I'm not quite clear what is going on. I'm somewhat new to vim scripting so any help with figuring out the issue is appreciated. </p>