Skip to main content
1 of 2
romainl
  • 42.3k
  • 5
  • 87
  • 118

You can do it very simply with:

function! ReplaceThisWithThat(this, that)
    execute "%s:" . a:this . "/" . a:that . "/g"
endfunction

Which will substitute every occurrence of a:this with a:that in the whole buffer.

If you want to perform that substitution on the content of some variable or register, you can use substitute() in your function:

function! ReplaceThisWithThat(something, this, that)
    return substitute(a:something, a:this, a:that, "g")
endfunction

which doesn't make much sense.

That said, everything you need to know is in :help eval.txt.

romainl
  • 42.3k
  • 5
  • 87
  • 118