aurum / ftplugin / diff.vim

"▶1 
scriptencoding utf-8
if !has('folding')
    finish
endif
if !exists('s:_sid')
    function s:Eval(expr)
        return eval(a:expr)
    endfunction
    let s:_sid=matchstr(s:Eval('expand("<sfile>")'), '\v\d+')
endif
let &l:foldexpr='<SNR>'.s:_sid.'_FoldExpr()'
let &l:foldtext='<SNR>'.s:_sid.'_FoldText()'
"▶1 foldexpr
function! s:FoldExpr()
    let line=getline(v:lnum)
    let nextline=getline(v:lnum+1)
    if line[:4] is# 'diff '
        return 1
    elseif nextline[:4] is# 'diff '
        return '<1'
    elseif line[:2] is# '@@ '
        return 2
    elseif nextline[:2] is# '@@ '
        return '<2'
    endif
    return '='
endfunction
"▶1 foldtext
function! s:FoldText()
    let line=getline(v:foldstart)
    if v:foldlevel==1
        if line =~# '\v^diff\ a\/(.{-})\ b\/\1'
            return matchlist(line, '\v^diff\ a\/(.{-})\ b\/\1')[1]
        elseif line =~# '\v^diff%(\ \-r\ \x+){1,2}'
            return substitute(line, '\v^diff%(\ \-r\ \x+){1,2}\ ', '', '')
        endif
    elseif v:foldlevel==2
        return substitute(line, '\m^@@[^@]\+@@ ', '', '')
    endif
endfunction
"▶1
" vim: ft=vim ts=4 sts=4 et fmr=▶,▲
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.