add better ruby fold method
This commit is contained in:
parent
d8abaef654
commit
ceb650b33e
24
vim/vimrc
24
vim/vimrc
@ -132,6 +132,9 @@ cmap w!! w !sudo tee % >/dev/null
|
|||||||
noremap <C-b> :r!xclip -sel c -o<CR><CR>
|
noremap <C-b> :r!xclip -sel c -o<CR><CR>
|
||||||
noremap <C-m> :w !xclip -sel c<CR><CR>
|
noremap <C-m> :w !xclip -sel c<CR><CR>
|
||||||
|
|
||||||
|
" Unfold everything upon opening a new file
|
||||||
|
"autocmd BufRead * normal zR
|
||||||
|
set foldlevelstart=2
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Filetype specific configuration. {{{
|
" Filetype specific configuration. {{{
|
||||||
@ -207,6 +210,23 @@ endfunction
|
|||||||
autocmd FileType ruby call RubyHook()
|
autocmd FileType ruby call RubyHook()
|
||||||
autocmd FileType eruby call RubyHook()
|
autocmd FileType eruby call RubyHook()
|
||||||
|
|
||||||
|
function RubyFold(lnum)
|
||||||
|
if getline(a:lnum) =~ '^\s*def\s' || getline(a:lnum) =~ '^\s*class\s' || getline(a:lnum) =~ '^\s*module\s'
|
||||||
|
return indent(a:lnum) / 2 + 1
|
||||||
|
endif
|
||||||
|
if getline(a:lnum) =~ '^\s*end'
|
||||||
|
return indent(a:lnum) / 2 + 1
|
||||||
|
endif
|
||||||
|
if getline(a:lnum - 1) =~ '^\s*end'
|
||||||
|
return indent(a:lnum - 1) / 2
|
||||||
|
endif
|
||||||
|
return '='
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function RubyFoldText()
|
||||||
|
return getline(v:foldstart) . ' +'
|
||||||
|
endfunction
|
||||||
|
|
||||||
function RubyHook()
|
function RubyHook()
|
||||||
setlocal tabstop=2
|
setlocal tabstop=2
|
||||||
setlocal shiftwidth=2
|
setlocal shiftwidth=2
|
||||||
@ -217,7 +237,9 @@ function RubyHook()
|
|||||||
set makeprg=rake
|
set makeprg=rake
|
||||||
|
|
||||||
" Folding
|
" Folding
|
||||||
set foldmethod=syntax
|
set foldmethod=expr
|
||||||
|
set foldexpr=RubyFold(v:lnum)
|
||||||
|
set foldtext=RubyFoldText()
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
Loading…
Reference in New Issue
Block a user