views:

475

answers:

4

I usually edit RUBY files in VIM. I want the methods(def...end) to fold. Could you please help me define the fold syntax?

A: 

eigenclass

site appears to be down, here's a google cache link:

anthony
Page doesn't exist?
John Weldon
+1  A: 

Assuming you've already got Ruby syntax highlighting setup and working, use the syntax mode for folding:

set foldmethod=syntax

This will give you folds on class .. end and def .. end, etc.

overthink
+1  A: 

I like to have everything fold by default, and this here will let you tweak a whole bunch of things related to folding. I do mostly Perl and C++ coding and I find it works well with that. Folding and unfolding is mapped to space key.

Here's what I have going in my vimrc:

  " Folding stuff
  hi Folded guibg=red guifg=Red cterm=bold ctermbg=DarkGrey ctermfg=lightblue
  hi FoldColumn guibg=grey78 gui=Bold guifg=DarkBlue
  set foldcolumn=2
  set foldclose=
  set foldmethod=indent
  set foldnestmax=10
  set foldlevel=0
  set fillchars=vert:\|,fold:\
  set foldminlines=1
 " Toggle fold state between closed and opened.
  "
  " If there is no fold at current line, just moves forward.
  " If it is present, reverse it's state.
  fu! ToggleFold()
     if foldlevel('.') == 0
         normal! l
     else
         if foldclosed('.') < 0
             . foldclose
         else
             . foldopen
         endif
     endif
     echo
  endf

" Map this function to Space key.
  noremap <space> :call ToggleFold()<CR>
Kyle Walsh
A: 

I think you put the cursor on the first line then zfnj where n is the number of lines to fold (so to fold 10 lines you woudl zf10j). I think it will also recognize syntax so like in PHP I do zf} to fold to the closing bracket. I don't code in Ruby, so I don't know if this works in Ruby.

From then on, to toggle, zo will open and zc will close.

dsrekab