Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Multi-line comments in perl code?

by tcf03 (Deacon)
on Jul 13, 2006 at 20:03 UTC ( #561064=note: print w/ replies, xml ) Need Help??


in reply to Multi-line comments in perl code?

if you use vim add the following to your .vimrc

set formatoptions=r
after your initial # comment goes here - each time you hit a newline, a # will be placed at the beginning... or/and to .vimrc
" comment out blocks " ma to mark beginning " put cursor at the end and hit F7 " code will be commented out map <F7> :'a,.s/^/#/gi^M:nohl^M map <F10> :'a,.s/^#//gi^M:nohl^M
I believe I got that last one from a thread here...

Ted
--
"That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved."
  --Ralph Waldo Emerson


Comment on Re: Multi-line comments in perl code?
Select or Download Code
Re^2: Multi-line comments in perl code?
by TheDamian (Priest) on Jul 14, 2006 at 14:00 UTC
    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
Node Status?
node history
Node Type: note [id://561064]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2014-09-17 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (94 votes), past polls