Charles E Campbell Jr wrote:
Meino Christian Cramer wrote:
From: Charles E Campbell Jr <[EMAIL PROTECTED]>
Subject: Re: Commenting out TeX-text line by line in V-mode
Date: Thu, 16 Nov 2006 13:34:16 -0500
How about
:[range]g/\S/s/^/%/
which means: over the selected range (which may be the visual
range), on all lines that
have some non-white-space character on them, insert a leading %.
OK, here's a more detailed explanation:
:[range] over the selected lines, which with visual selection
will appear as '<,'> .
Those are marks set by the visual selection.
g/pattern/cmd for any lines which match the given pattern, in this
case \S , do the specified cmd.
So, the cmd is performed for any line that has a
non-whitespace character in it.
Thus, empty lines and lines with just whitespace (tabs
and spaces) will not match.
Now, the aforementioned cmd is
s/^/%/ Substitute a % at the beginning of the current line.
What you asked for was to do something (comment out lines) given a
condition (that the line must not be empty). So the :g/pattern/cmd
allows one to do a command (s/^/%/) only when the line matched a pattern
(that implied that the line was not empty).
Regards,
Chip Campbell
It should be possible (though less obvious) to do it with only a substitute.
Let's try:
:'<,'>s/^.*\S.*$/# \0
i.e. prepend a hash sign and a space wherever we find start-of-line, zero or
more of anything, one nonblank, zero or more of anything, end-of-line (in the
range, here shown as a Visual area).
Best regards,
Tony.