Re: Commenting out TeX-text line by line in V-mode

2006-11-17 Thread Charles E Campbell Jr

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





Re: Commenting out TeX-text line by line in V-mode

2006-11-17 Thread A.J.Mechelynck

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.


Re: Commenting out TeX-text line by line in V-mode

2006-11-17 Thread Charles E Campbell Jr

A.J.Mechelynck wrote:



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).



OK, here's another possible but less obvious method, even a bit shorter:

:','s/^.*\S\^/%/

This one uses a concat, and depends on having the last concat be the 
one used for substitution.

What it means:

:','  over the visually selected range
s   substitute the pattern that begins with something but has a 
non-whitespace character,

AND matches the beginning-of-line

with a % in the place of the last concat (ie. the beginning-of-line).

Regards,
Chip Campbell



Re: Commenting out TeX-text line by line in V-mode

2006-11-16 Thread Dmitriy Yamkovoy

Or you could skip step one, and only add percent signs on the lines
with anything in them:

(select lines visually)
:','s/^\(.\)/% \1

-Dmitriy

On 11/15/06, A.J.Mechelynck [EMAIL PROTECTED] wrote:

Meino Christian Cramer wrote:
 Hi,

  a question more driven by curiosity than by the need to change
  anything.


  Suppose you have the following TeX-text:

 bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
 foo bar gnu gnats
 bla blabla foo bar gnu gnats

 bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
 foo bar gnu gnats

 bla blabla foo bar gnu gnats


  and because this text is so fullfilled with wisdom and knowledge,
  that no one else than you will be able to handle its contents
  carefully ;) you decide to comment it out to not to harm the public.
  As a vim newbie I would do that using block oriented visual mode on
  the first line and I-nserting a '%' (TeX's comment sign), which
  results in:

  %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  %  foo bar gnu gnats
  %  bla blabla foo bar gnu gnats
  %
  %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  %  foo bar gnu gnats
  %
  %  bla blabla foo bar gnu gnats


  So far so nice...it works.

  But would be there a way to acchieve the following commenting:

  %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  %  foo bar gnu gnats
  %  bla blabla foo bar gnu gnats

  %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  %  foo bar gnu gnats

  %  bla blabla foo bar gnu gnats

  (blank lines not commented out) by a similiar simple command like
  CTRL-v SHIFT-i textESC ?

  As said: This Q is mostly curiosity - based...I even dont know,
  whether haveing such a feature would be really useful or not.

  But as always: Experimenting is fun! :O)

  Keep editing!
  mcc



1. Add all percent signs like you did above, even before blank lines.
2. Replace empty comments by blank (i.e. empty) lines as follows:

:%s/^%\s*$//


Best regards,
Tony.



Re: Commenting out TeX-text line by line in V-mode

2006-11-16 Thread Meino Christian Cramer
From: A.J.Mechelynck [EMAIL PROTECTED]
Subject: Re: Commenting out TeX-text line by line in V-mode
Date: Thu, 16 Nov 2006 05:20:13 +0100

 Meino Christian Cramer wrote:
  Hi,
  
   a question more driven by curiosity than by the need to change
   anything.
  
   
   Suppose you have the following TeX-text:
  
  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  foo bar gnu gnats 
  bla blabla foo bar gnu gnats 
  
  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
  foo bar gnu gnats 
  
  bla blabla foo bar gnu gnats 
  
  
   and because this text is so fullfilled with wisdom and knowledge,
   that no one else than you will be able to handle its contents
   carefully ;) you decide to comment it out to not to harm the public.
   As a vim newbie I would do that using block oriented visual mode on
   the first line and I-nserting a '%' (TeX's comment sign), which
   results in:
  
   %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
   %  foo bar gnu gnats 
   %  bla blabla foo bar gnu gnats 
   %  
   %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
   %  foo bar gnu gnats 
   %  
   %  bla blabla foo bar gnu gnats 
  
  
   So far so nice...it works.
  
   But would be there a way to acchieve the following commenting:
  
   %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
   %  foo bar gnu gnats 
   %  bla blabla foo bar gnu gnats 
 
   %  bla blabla foo bar gnu gnats bla blabla foo bar gnu gnats bla blabla
   %  foo bar gnu gnats 
 
   %  bla blabla foo bar gnu gnats 
  
   (blank lines not commented out) by a similiar simple command like
   CTRL-v SHIFT-i textESC ?
  
   As said: This Q is mostly curiosity - based...I even dont know,
   whether haveing such a feature would be really useful or not.
  
   But as always: Experimenting is fun! :O)
  
   Keep editing!
   mcc
   
  
 
 1. Add all percent signs like you did above, even before blank lines.
 2. Replace empty comments by blank (i.e. empty) lines as follows:
 
   :%s/^%\s*$//
 
 
 Best regards,
 Tony.
 

Hi Tony,

 yes...I know that (which is an exception... ;)

 I thought there would be one command to achieve the same effect
 instead of doing it the wrong way first and the correct
 it by an additional command...

 Keep editing!
 mcc