Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I know that this is an old node. And that I have already commented on it. However, I wanted to add some updates.

I had a regex mapped to comment out lines or blocks of code and another to uncomment them. I always hated that this killed my "previous search expression" so that I could not go through a file looking for a pattern, comment out the line, and go to the next occurrence without re-issuing the search command. I always thought "There must be a better way. After OSCON 2007, I found that better way:

function! Comment() let l:line = "#".getline(".") call setline(".",l:line) endfunction map ## :call Comment()<cr> function! UnComment() let l:line = getline(".") let l:pos = stridx(l:line,"#") if l:pos > -1 let l:line = strpart(l:line,0,l:pos).strpart(l:line,l:pos+1) endif call setline(".",l:line) endfunction map !# :call UnComment()<cr>

I also got tired of the fancy status line function not working inside closures because sub was indented. So, I did some poking at the code (that a coworker had put together) and made some minor fixes:

if has( "folding" ) set statusline=%f%{CurrSubName()}\ %m%h%r\ %=%25(%-17(%l\,%c%V%)\ %p +%%%) set laststatus=2 set maxfuncdepth=1000 endif function! CurrSubName() let g:subname = "" let g:subrecurssion = 0 " See if this is a Perl file let l:firstline = getline(1) if ( l:firstline =~ '#!.*perl' || l:firstline =~ '^package ' ) call GetSubName(line(".")) endif return g:subname endfunction function! GetSubName(line) let l:str = getline(a:line) if l:str =~ '^\s*sub\>' let l:str = substitute( l:str, ' *{.*', '', '' ) let l:str = substitute( l:str, '^\s*sub *', ': ', '' ) let g:subname = l:str return 1 elseif ( l:str =~ '^}' || l:str =~ '^} *#' ) && g:subrecurssion >= 1 return -1 elseif a:line > 2 let g:subrecurssion = g:subrecurssion + 1 if g:subrecurssion < 190 call GetSubName(a:line - 1) else let g:subname = ': <too deep>' return -1 endif else return -1 endif endfunction

Share and enjoy.

Ivan Heffner
Sr. Software Engineer
WhitePages.com, Inc.

In reply to Re: .vimrc for perl programmers by Codon
in thread .vimrc for perl programmers by nferraz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (12)
    As of 2014-08-20 16:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (119 votes), past polls