[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Vim question



On Sun, Oct 23, 2005 at 02:50:48AM +0200, Paolo Pantaleo wrote:
> How can i comment 10 lines of code in a shot? That is, how can i add a

1) Go to the first line of the code that you want to
   comment.
2) Press <esc> to get into command mode rather than insert
   mode.
3) Press 'v' to begin Visual Select mode.
4) Navigate with the arrow keys or your chosen navigation
   keys until you've selected all the lines you care about.
5) Type

   :s/^/#

   to add a '#' at the beginning of every line. If you
   wanted to comment C code, you could do

   :s#^#//

   to put a '//' at the beginning of every line. Just to be
   clear, that last substitution command is equivalent to

   :s/^/\/\/

   but is, I think, prettier.

If you wanted to instead replace

line 1
line 2
line 3

with

/*
line 1
line 2
line 3
*/

I'm not sure how you'd do it. Perhaps others do.

-- 
Stephen R. Laniel
steve@laniels.org
+(617) 308-5571
http://laniels.org/
PGP key: http://laniels.org/slaniel.key

Attachment: signature.asc
Description: Digital signature


Reply to: