Unix Tip #4608- October 23, 2023


SEARCH : Home : Help : Today's Tip

COMMENT OUT MULTIPLE LINES


Ever wanted to comment out
multiple lines of code while
writing shell
scripts in vi, but didn't want
to pound your keyboard for half
an hour doing it?

(I#Escape j.j.j.j. = carpal tunnel)

Here's the nerdy way to do it:

:.,+N-1 s/^/#/g

Where N-1 is the number of lines
minus one that you want to comment
out, and s/^/#/g is the regular
expression (the pattern between the
first two slashes is what you want
to replace, in this case the
beginning of the line, and the
pattern between the last two slashes
is what you want to replace it with).

For example, if you're a bad
coder like me and want to comment
out 500 lines of code, you would do:

:.,+499 s/^/#/g



This tip generously supported by: maddox@xmission.com

NOTE: All tips provided are USE AT YOUR OWN RISK. Tips are submitted by various unix admins around the globe. UGU suggest you read and test each tip in a non-volitile environment before placing into production.


LAST 5 TIPS
4607 - HOW MUCH SOLARIS MEMORY?
4606 - EDITING OF LARGE FILES
4605 - LEAKING MEMORY?
4604 - TRUSS THE PID.....
4603 - VERIFY AFTER VACATIONS


I want to SUBSCRIBE and get a UGU Tip everyday.
I want to UNSUBSCRIBE and NOT get a UGU Tip everyday.

If you have a UNIX TIP let us know, we just may use it:
(All tips become the property of the Unix Guru Universe)
Email Address:

Yes, email me a Hot Unix Tip everday.

Enter Hot Unix Tip (optional):

Yes, I will support this tip

Captcha (not case sensitive):


Please enter the above letters:


HOME | Flavors | Admin | Network | Security | S/W | Help | Events | Vendors | Careers | Internet
About | Add Link | Feedback | Search

Copyright © 1994-2005 Unix Guru Universe