Created
October 16, 2010 09:15
-
-
Save Raimondi/629606 to your computer and use it in GitHub Desktop.
Unified patch file folding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" From jamessan#[email protected] | |
" Folding for unified diffs | |
function! DiffFoldLevel(lineno) | |
let line = getline(a:lineno) | |
if line =~ '^Index:' | |
return '>1' | |
elseif line =~ '^===' || line =~ '^RCS file: ' || line =~ '^retrieving revision ' | |
let lvl = foldlevel(a:lineno - 1) | |
return lvl >= 0 ? lvl : '=' | |
elseif line =~ '^diff' | |
return getline(a:lineno - 1) =~ '^retrieving revision ' ? '=' : '>1' | |
elseif line =~ '^--- ' && getline(a:lineno - 1) !~ '^diff\|^===' | |
return '>1' | |
elseif line =~ '^@' | |
return '>2' | |
elseif line =~ '^[- +\\]' | |
let lvl = foldlevel(a:lineno - 1) | |
return lvl >= 0 ? lvl : '=' | |
else | |
return '0' | |
endif | |
endf | |
setlocal foldmethod=expr | |
setlocal foldexpr=DiffFoldLevel(v:lnum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment