title: How do you do a search and replace inside a vim function?
body: <p>I'm trying to a write a function that runs search and replace on a range.</p>
  
  <p>I know that one can do <code>:2,5 s/some pattern/something else/</code> to do this as a vim command, but I can't figure out how this would work inside a function definition. Initially, I tried</p>
  
  <pre><code>function! MyFunc() range
    a:firstline,a:lastline s/some pattern/something else/
  endfunction
  </code></pre>
  
  <p>but when I try to load that function in, I get the error <code>Missing :endfunction</code>. I also tried with call, as I've noticed in other tutorials and examples that sometimes call is used in situations like this. I tried both <code>call a:firstline,a:lastline s/some pattern/something else/</code> and <code>a:firstline,a:lastline call s/some pattern/something else/</code>. With this, the function loaded. But when I tried calling the function with doing <code>:2,4 call MyFunc()</code>, I get a <code>Missing parenthesis</code> error pointing at the search/replace line.</p>
  
  <p>Can anyone help me with this? I have yet to find any examples of how to do search and replace in a function call.</p>
  
  <p>Thanks</p>