From: "A.J.Mechelynck" <[EMAIL PROTECTED]> Subject: Re: Commenting out TeX-text line by line in V-mode Date: Fri, 17 Nov 2006 16:18:14 +0100
> 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. Hi Tony! :) There are more ways to confuse a newbie... :O) Let me explain just to see whether I got this riddle solved this time by myself: '<,'> for a range marked in visual mode s/ substitue/replace ^.*\S.*$ match "beginning of line,something,at least one non-whitespace,something,end of line" / with # \0 "# ",the whole line Right? :) vim-sudoku.... ;)))) Have a nice weekend! mcc