I am trying to create a simple vim script function and am having problems. This function should take two input strings and run a search and replace all their instances. I have the following right now:
function! FindAndReplaceAll(from, to) echo a:from :%s/a:from/a:to/gc endfunction
When I do this:
:call FindAndReplaceAll("test", "test2")
Echo a: from works correctly, but:% s ... acts instead of the letters from and to. I noticed that my vim syntax simulator does not even highlight these variables, so I seem to have a basic syntax problem.
My questions:
- What is the correct syntax with this? I would appreciate an explanation of why, not just an answer. Why is this wrong?
In any case, so that it is called as
: call FindAndReplaceAll (test, test2)
Therefore, I do not need to add quotes ...
source share