Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Multi-line comments in perl code?

by TheDamian (Vicar)
on Jul 14, 2006 at 10:00 UTC ( [id://561215]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re: Multi-line comments in perl code?
in thread Multi-line comments in perl code?

I use a variant of that approach for Vim. In my .vimrc file:
"=====[ Add or subtract comments ]=============================== function ToggleComment () let currline = getline(".") if currline =~ '^#' s/^#// else s/^/#/ endif endfunction map <silent> # :call ToggleComment()<CR>j0
Thereafter hitting # in Normal mode either inserts a comment marker(if the line doesn't have one) or removes it (if one was already there). Either way, the cursor is then moved to the next line ready to dish out more of the same treatment.

The upshot is that a series of #'s runs you down the file, toggling the commentedness of each line.

However, for inserting/removing long blocks of comments I find Visual mode the easiest solution. Navigate to the start of the first (or last) line on which you want to insert comments. Then type CTRL-V to enter Visual Block mode. Then navigate to the other end of the block of code you want to comment, using any of the normal Vim motion commands. Then type I#<ESC> and...voilà!

To subsequently remove a block of column-1 comments: CTRL-V(navigate to other end)x

UPDATE: Added missing if line and corrected else (thanks Jack!)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://561215]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.