Mosh wrote:
I noticed gmail folds large mail when contiguous lines have same prefix.
It would also work for:
find . | vim -
and vim could fold directories recursively by number of slashes?
Then users dont have to figure out the complexities of folding mode setup?
any ideas how to do it?
Hi Mosh,
I wrote an ftplugin/folddirs.vim script that I use to quickly scan the
listings produced by `rsync -v` which on large file sets can generate
output that far exceeds my manual reviewing capabilities :-)
It folds based on the common prefix of lines which makes it really slow
but on the other hand it does the job and I don't think there's an easy
way to speed this up without reaching for C instead of Vim script.
I've attached the script, if you save it as ~/.vim/ftplugin/folddirs.vim
and then do :set ft=folddirs in the buffer containing the `find` output
it should work.
- Peter Odding
" A folding expression that folds contiguous pathnames based on common prefix.
function! FoldDirs_Expr(lnum)
let a = split(getline(a:lnum - 1), '/')
let b = split(getline(a:lnum), '/')
let i = 0
while i < len(a) && i < len(b) && a[i] == b[i]
let i += 1
endwhile
return i
endfunction
function! FoldDirs_Text(foldstart, foldend)
let a = split(getline(a:foldstart), '/')
let b = split(getline(a:foldend), '/')
let i = 0
while i < len(a) && i < len(b) && a[i] == b[i]
let i += 1
endwhile
let common_path = join(a[0 : i - 1], '/')
let folded_lines = a:foldend - a:foldstart
return printf('%s: %d lines', common_path, folded_lines)
endfunction
setlocal foldexpr=FoldDirs_Expr(v:lnum)
setlocal foldtext=FoldDirs_Text(v:foldstart,v:foldend)
setlocal foldmethod=expr
setlocal foldenable
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php