On Fri, Oct 04, 2002 at 10:48:15AM +1000, Angus Lees wrote:
> At 01 Oct 2002 11:27:17 +1000, Simon Wong wrote:
> > vi gurus,
> > I want to comment out every line in a file (inetd.conf) but not the ones
> > that already are.
> 
> *cough* M-x comment-region *cough*
> 
> (and of course there's a matching uncomment-region)

... in emacs Gus, in emacs ...

Now Simon, seeing as your editor of choice (vi) is somewhat more elegant,
you can do the following instead:

:%s/^[^#]/#

which, apart from being shorter than the emacs command, is also more
adaptable to other situations than the single purpose "M-x comment region".

dissecting this regular expression briefly (this form is worth learning):

        :                is the vi command line
        %                means to work on every line in the file
        s/ ... / ...     means to do a substitution (stuff matching what's
                         after the first slash is replaced with the stuff
                         after the second slash)
        ^                means the beginning of the line
        [^#]             means any character other than #

in english:

    on every line of the file, put a hash at the beginning, if there is
    not a hash there already.

which is basically what you asked for :)

cheers,

Conrad.
(I edit both ways)
-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to