Reputation: 43
This command
%s#^#/*
and this command
%s#$#*/
works fine in vi editor on ubuntu 14.04 when I execute them separately one after another.
What I need is execute them both in one line like
%s#^#/* <bar> %s#$#*/
I also tried | and ; and CR as separator and always get error 488 trailing character
Upvotes: 4
Views: 276
Reputation: 17497
In my vim 7.4 patch 769 this works very well.
:%s/foo/FOO/ | %s/bar/BAR/
It looks like you have omitted the final separator character from your substitutions. Vim doesn't know where your replacement string ends without having the terminating #
chars in there. When doing a usual command of one substitution, vim treats the end of the command as the terminating separator if one is not to be found.
For instance, it works if you omit the terminator in the last substitution of the command:
:%s/foo/FOO/ | %s#bar#BAR
And finally a quick tip regarding to your subs. You can wrap a line in text with a single substitution with some basic capture group magic. Match for the whole line and use &
in the replacement to reuse the matched text:
:s#.*#/* & */
Upvotes: 2