> " file begin - lots_of_replace.vim
> let from1 = "xxxxx" " more specific string
> let to1 = "yyyyy"
> let from2 = "xxx" " less specific string
> let to2 = "\x79yy" " or \u0079 (=y)
>
> "for l in range(line('$')+1)
> " call setline(l, substitute(getline(l), from1, to1, 'g') )
> " call setline(l, substitute(getline(l), from2, to2, 'g') )
> "endfor
>
> " It works!!! ^^^ :)
>
> mark a
> %s/$from1/$to1/g
> %s/$from2/$to2/g
> 'a
>
> " It does not works! ^^^ :( Why?
> " file end - lots_of_replace.vim
The "%s/foo/bar/" notation is for fixed (not variable) regexp
strings only. Your original request didn't mention trying to
build the substitutes dynamically, so I assumed they were fixed
regexps. It's looking for the literal text "$from1", not the
value assigned to "from1" (namely "xxxxx"). So you'd want to use
%s/xxxxx/yyyyy/g
%s/xxx/\x79yy/g
It can be hacked using the exec() command:
exec '%s/'.from1.'/'.to1.'/g'
exec '%s/'.from2.'/'.to2.'/g'
with varying degrees of escaping as needed around the from[12]
and to[12]. You can read about the escape function at
:help escape()
-tim
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---