Categories

 

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

What I'm Doing...

IMG00015.jpgIMG00017.jpgFallColors.jpgSpringFirst snow of the seasonTail Wind

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/Bookmark

Related posts:

  1. Grep for multiple stuff in one file Update: See the comments to see how to do this...
  2. Unix tar tricks One of the most common programs on Linux systems for...
  3. Sending email with a body and attachment from UNIX It is easy to send a text file as the...
  4. Shutdown unused windows service Download the tool from http://www.smartpcutilities.com/ to shutdown services not used...

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>

Powered by WP Hashcash