Categories

 

February 2010
M T W T F S S
« Jan   Mar »
1234567
891011121314
15161718192021
22232425262728

What I'm Doing...

PlaytimePriya and KunalIMG00015.jpgIMG00017.jpgFallColors.jpgSpring

comment multiple lines in vi

The comment symbol for Unix scripts is typically “#”. You can use the same concept for files for other programming languages. My vi commands below use the “#” symbol.
If you want to comment 5 lines in a file -

  1. Go to the first line you want to comment
  2. Make sure you are in the command mode. (Hit ESC).
  3. Now type the following “:.,+N-1 s/^/#/g”, Where N is the number of lines you want to comment. In this case it would be
    :.,+4 s/^/#/g
                 

You can also comment till a unique word in a file. For instance here is a snippet of a file -

line one
line two
line three
line four
line five

Suppose you want to comment from line two till line four. Go to the beginning of “line two” and type the following after you are in the command mode

:.,/line four/ s/^/#/g
Share

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>