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
.
substitute
command isn't satisfying enough for you or it's just for vimscript training purpose?