On Tue, Oct 01, 2002 at 12:42:51PM +1000, Tom wrote:
> >
> > %s/^[^#]/#/
>
> For regular expression (regex) newbies, the two carets ('^')
> in this expression have different meanings.
>
> The first caret means "start of line". The second caret
> immediately follows the opening square bracket of a character
> class, so it means "NOT any of the characters listed within
> the square brackets".
Which shows you the problem with Tony and Andrew's
replies :-) (bad programmer, no biscuit!)
They're replacing all 'not hashes'at the beginning
of the line with hashes, and wiping out valid chars
in the process.
Christopher's solution is to search for all lines
with non hash at the beginning and only apply the
substitution there:
:g/^[^#]/s/^/#/
is
g # globally, i.e. all lines, same as %
/^[^#]/ # search for lines with first char not hash
s/^/#/ # and 'substitute' the beginning of the line
# with a hash.
# I put substitute in quotes because the
# beginning of the line is a sort of imaginary
# character, so you're not so much substituting
# as inserting.
Regards,
Matt
--
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug