Vim regex

I was wanting to start some comments in a large Perl module the other day and not really had to use Vim’s regexp to any great degree because I know Perl I decided to see if it could be done.
I decided to add a little bit of pod above every funcion. The following was the result Remember In vim the ^M is a control character for carriage return and can be achieved by holding down the control key and pressing carriage return.
The following regex
:%s/^sub\(.*\) {\(.*$\)/=head \1\(\)^M^MDescrition:^M^M=cut^Msub \1{\2/
changes
sub summit_sub {
stuff;
}
to
=head summit_sub()
Descrition:
=cut
sub summit_sub{
stuff;
}
The following regex
:%s/^sub\(.*\)\n{\(.*$\)/=head \1\(\)^M^MDescrition:^M^M=cut^Msub \1{\2/
changes
sub summit_sub
{
stuff;
}
to
=head summit_sub ()
Descrition:
=cut
sub summit_sub {
stuff;
}

Leave a Reply

Your email address will not be published. Required fields are marked *