DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Vim Folding For RSpec Editing

02.15.2007
| 5941 views |
  • submit to reddit
        
" fold text between context and specify
function! ShowRSpecContext()
  let spec_idx = search('specify\s\+".\+"', 'Wbn', '^')
  let ctx_idx  = search('context\s\+".\+"', 'Wbn', '^')
  if spec_idx && ctx_idx
    exec (ctx_idx+1).','.(spec_idx-1).'fold'
  endif
endfunction

" fold text between all contexts and specify lines
function! ShowRSpecAnnotation()
 call cursor('$', 0)
 try
   foldo!
 catch
 endtry
 let cur_line = line('$')
 while cur_line > 0
   let prev_spec = search('\(context\|specify\)\s\+".\+"', 'Wb', '^')
   if ! prev_spec
     break
   endif
   exec (prev_spec).','.cur_line.'fold'
   let cur_line=prev_spec-1
 endwhile
endfunction
command! Sx :call ShowRSpecContext()
command! Sa :call ShowRSpecAnnotation()