The first step is implementing the line-oriented part of vi, called ex, based on the manual from the sourceforge project. My version is based on bililiteRange, and depends on the bililiteRange utilities and undo plugin.
Use it simply as
bililiteRange(textarea).ex('%s/foo/bar/');, passing the ex command to the
s/\w/x/ rather than
s/[:class:]/x/, and use
?/.../ rather than