Wikia

Vim Tips Wiki

Changes: Folding for diff files

Edit

Back to page

(Add Related plugins section with a link to diff_fold.vim.)
(Insert TipProposed template + manual clean)
 
Line 1: Line 1:
When you want to inspect large diff/patch files, following fold function may come handy. Put it in your ftplugin/diff.vim file or equivalent.
+
{{TipProposed
<code>
+
|id=0
setlocal foldmethod=expr foldexpr=DiffFold(v:lnum)
+
|previous=0
function! DiffFold(lnum)
+
|next=0
let line = getline(a:lnum)
+
|created=June 24, 2013
if line =~ '^\(diff\|---\|+++\|@@\) '
+
|complexity=basic
return 1
+
|author=
elseif line[0] =~ '[-+ ]'
+
|version=7.0
return 2
+
|subpage=/2013
else
+
|category1=
return 0
+
|category2=
endif
+
}}
endfunction
+
When inspecting large diff/patch files, the following fold function is handy. Put it in your <code>ftplugin/diff.vim</code> file or equivalent.
</code>
+
<pre>
  +
setlocal foldmethod=expr foldexpr=DiffFold(v:lnum)
  +
function! DiffFold(lnum)
  +
let line = getline(a:lnum)
  +
if line =~ '^\(diff\|---\|+++\|@@\) '
  +
return 1
  +
elseif line[0] =~ '[-+ ]'
  +
return 2
  +
else
  +
return 0
  +
endif
  +
endfunction
  +
</pre>
   
 
==Related plugins==
 
==Related plugins==
* {{script|id=3262|text=diff_fold.vim}} folds changesets, files, and hunks in (Mercurial, and similar) diff output.
+
*{{script|id=3262|text=diff_fold.vim}} folds changesets, files, and hunks in (Mercurial, and similar) diff output
  +
  +
==Comments==

Latest revision as of 10:39, January 31, 2014

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created June 24, 2013 · complexity basic · version 7.0

When inspecting large diff/patch files, the following fold function is handy. Put it in your ftplugin/diff.vim file or equivalent.

setlocal foldmethod=expr foldexpr=DiffFold(v:lnum)
function! DiffFold(lnum)
  let line = getline(a:lnum)
  if line =~ '^\(diff\|---\|+++\|@@\) '
    return 1
  elseif line[0] =~ '[-+ ]'
    return 2
  else
    return 0
  endif
endfunction

Related pluginsEdit

  • diff_fold.vim folds changesets, files, and hunks in (Mercurial, and similar) diff output

CommentsEdit

Around Wikia's network

Random Wiki