Prepend only lines with text in vim
Something like this should work:
:%s/^\(.*[^\n]\)$/* \1/
EDIT Since you asked for a breakdown of the regular expression:
:%
All lines
s/
Beginning of substitute command; begin pattern
^
Beginning of line
\(
Beginning of group we want to preserve. This will be important later.
.*
Any number of characters
[^\n]
Some character besides newline
\)
End of group
$
End of line
/
End of pattern, beginning of substitution
* \1
Insert *
, then the first group that we selected on the left.
/
End of substitution and command
Try
:g/\S/s/^/* /
g/\S/
is a range operator (analogous to %
except it selects all lines with a non-blank character).
s/^/* /
inserts "* " at the beginning of each selected line.
This avoids the issue with @objectified's answer of putting the prefix on the 1st line of a double blank line sequence.
The following appends " *" at the end of each selected line.
:g/\S/s/$/ */
If the blank line are truly empty, containing only NewLine then this works.
:g/./s/^/*
Explanation
:g/
Global Substitute begin search for pattern
.
Match any character except new line :help /.
/^
Match start of line
/*
Insert the *