I would like to use the arguments passed to a function, as an argument to replace a search.
Something like this:
function! Myfunction(...) %s/hello/ goodBye a:1, a:2/g endfunction
Does anyone know how it can be done?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
If you can have any number of parameters, you'd have the choice between the following (untested) solutions
:exe '%s/hello/ goodbye '.join(a:000, ', ').'/'
(expecting the parameters contain no backslashes) or
:%s/hello/\=' goodbye '.join(a:000, ', ')/
This second solution works only when the dynamic part is used in the replacement text, not in the searched pattern.