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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.