Use \=
in the :s
replacement part to execute vim expressions.
:%s/\d\+/\=join(sort(split(tr(submatch(0), '01234567', '23670145'), '\zs')), '')/g
:%s/.*/\=join(sort(split(submatch(0), ', ')), ', ')
You could also use Tim Pope's Abolish plugin for the :Subvert
command for instead of tr()
. e.g. :%S/{0,1,2,3,4,5,6,7}/{2,3,6,7,0,1,4,5}/g
For more help see:
:h :s\=
:h sort(
:h join(
:h split(
:h tr(