Vi commenting out

Roger Oberholtzer roger
Mon Oct 16 23:36:48 PDT 2006


On Mon, 2006-10-16 at 21:27 -0500, Michael Hipp wrote:
> Bill Campbell wrote:
> > On Mon, Oct 16, 2006, Michael Hipp wrote:
> >> Is there any simple trick for having vi comment out a whole range of lines by 
> >> placing a '#' in front of them? The manual method of i # ESC j is rather 
> >> tedious if there is a big section to be done.
> > 
> > Position the cursor on the top line you want to comment.  Press
> > ``ma'' (Mark A) to set a mark there.
> > 
> > Position the cursor at the bottom of the range.  Enter this
> > command which says to operate over the range from the marked a to
> > the current line ('a indicates the mark a, `b would be mark b).
> > 
> > :'a,.s/^/#/<RETURN>
> > 
> > One could also do ``I#<ESC>'' then press ``j.'' to go down a line
> > and repeat the previous command for as many lines as you like.
> 
> Thanks, Bill. One or the other should do the job depending on how long the 
> section may be.

Another way depends on the language. If it is Tcl, for example, I can
surround the code with

if {0} {

	code to comment out

}

Changing the 0 to a 1 enables the code again. May sound odd, but in
script languages, the comment symbol is a command. So 100 lines of
comments is really 100 commands to interpret, the command being to
ignore the line or whatever the comment syntax is. The method above does
not add to the runtime work.

> 
> Michael
> _______________________________________________
> Linux-users mailing list ( Linux-users at linux-sxs.org )
> Unsub/Password/Etc: http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
> 
> Need to chat further on this subject? Check out #linux-users on irc.linux-sxs.org !
-- 
Roger Oberholtzer

OPQ Systems AB
Ramb?ll Sverige AB
Kapellgr?nd 7
P.O. Box 4205
SE-102 65 Stockholm, Sweden

Tel: Int +46 8-615 60 20
Fax: Int +46 8-31 42 23




More information about the Linux-users mailing list