Permalink
Browse files

a better fold text

  • Loading branch information...
1 parent 7c4d4eb commit 38fc7a928a5a705f012088b033a4044817737f35 @andersonfreitas committed May 24, 2012
Showing with 35 additions and 0 deletions.
  1. +35 −0 vim/vimrc
View
@@ -108,6 +108,41 @@ set statusline +=0x%04B\ " character under cursor
autocmd FileType ruby setlocal foldmethod=syntax foldlevelstart=99 nofoldenable
autocmd FileType css setlocal foldmethod=indent shiftwidth=2 tabstop=2 foldlevelstart=99 nofoldenable
+set foldtext=MyFoldText()
+function! MyFoldText()
+ let line = v:folddashes.getline(v:foldstart)
+ if match( line, '^[ \t]*\(\/\*\|\/\/\)[*/\\]*[ \t]*$' ) == 0
+ let initial = substitute( line, '^\([ \t]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' )
+ let linenum = v:foldstart + 1
+ while linenum < v:foldend
+ let line = getline( linenum )
+ let comment_content = substitute( line, '^\([ \t\/\*]*\)\(.*\)$', '\2', 'g' )
+ if comment_content != ''
+ break
+ endif
+ let linenum = linenum + 1
+ endwhile
+ let sub = initial . ' ' . comment_content
+ else
+ let sub = line
+ let startbrace = substitute( line, '^.*{[ \t]*$', '{', 'g')
+ if startbrace == '{'
+ let line = getline(v:foldend)
+ let endbrace = substitute( line, '^[ \t]*}\(.*\)$', '}', 'g')
+ if endbrace == '}'
+ let sub = sub.substitute( line, '^[ \t]*}\(.*\)$', '...}\1', 'g')
+ endif
+ endif
+ endif
+ let n = v:foldend - v:foldstart + 1
+ let info = " " . n . " lines "
+ let sub = sub . " "
+ let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' )
+ let fold_w = getwinvar( 0, '&foldcolumn' )
+ let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 )
+ return sub . info
+endfunction
+
" Using tabs in haml files
autocmd FileType haml setlocal noexpandtab

0 comments on commit 38fc7a9

Please sign in to comment.