I am trying to create a simple vim script function and I am having trouble. This function needs to take two input strings and run the search and replace all instances of them. I have the following right now:
function! FindAndReplaceAll(from, to)
echo a:from
:%s/a:from/a:to/gc
endfunction
When I do:
:call FindAndReplaceAll("test", "test2")
The echo a:from works correctly but the :%s... is acting on the from and to literals instead. I noticed my vim syntax high lighting isn't even highlighting those as variables so I seem to have a basic syntax problem.
My questions are:
- What is the correct syntax with this? I would appreciate an explanation of why rather than just the answer. Why is the above incorrect?
Anyway to allow for this to be called as
:call FindAndReplaceAll(test, test2)
So I don't have to add quotes...