From ab18682faed46e837e1bf2919d6b0d6b977e1b32 Mon Sep 17 00:00:00 2001 From: Petr Uzel Date: Thu, 28 Aug 2008 00:00:00 +0000 Subject: Version 0.1: Initial upload --- README | 19 ++++++++ ftplugin/diff_navigator.vim | 106 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 README create mode 100644 ftplugin/diff_navigator.vim diff --git a/README b/README new file mode 100644 index 0000000..74ee62f --- /dev/null +++ b/README @@ -0,0 +1,19 @@ +This is a mirror of http://www.vim.org/scripts/script.php?script_id=2361 + +Simple script that helps navigation in unified diffs (patches). + +Together with external utility filterdiff (part of patchutils) it provides DiffAnnotate command that tags all hunks with their number and name of the changed file. + +DiffShowHunk command displays annotation of the current hunk (useful when inside a big hunk). + +DiffNextFile and DiffPrevFile command can be used to quickly skip to next/previous changed file. + +DiffNextHunk and DiffPrevHunk quickly skips to next/previous hunk. + +Since the default (,),{ and } mappings are not much useful in diffs, the plugin remaps these in the following way: +} => DiffNextFile +{ => DiffPrevFile +) => DiffNextHunk +( => DiffPrevHunk + + diff --git a/ftplugin/diff_navigator.vim b/ftplugin/diff_navigator.vim new file mode 100644 index 0000000..fa4f5b1 --- /dev/null +++ b/ftplugin/diff_navigator.vim @@ -0,0 +1,106 @@ +" ============================================================================ +" File: diff_navigator.vim +" Description: Filetype plugin to ease navigation in (unified) diffs +" Maintainer: Petr Uzel +" Version: 0.1 +" Last Change: 27 Aug, 2008 +" License: This program is free software. It comes without any warranty, +" to the extent permitted by applicable law. You can redistribute +" it and/or modify it under the terms of the Do What The Fuck You +" Want To Public License, Version 2, as published by Sam Hocevar. +" See http://sam.zoy.org/wtfpl/COPYING for more details. +" +" Bugs: Send bugreports/patches directly to me via mail +" Dependencies: filterdiff (part of patchutils project) +" +" +" TODO: show current hunk in status line +" TODO: delete hunk/whole file diff - like http://www.vim.org/scripts/script.php?script_id=444) +" TODO: incorporate more patchutils functionality +" TODO: something like taglist for diff (shows all files/hunks in the diff) +" TODO: option for *Next|Prev* funtions to wrap around end of file +" ============================================================================ + + +" Only do this when not done yet for this buffer +if exists("b:did_ftplugin") + finish +endif +let b:did_ftplugin = 1 + +" Annotate each hunk with it's number and name of the changed file +if !exists("*s:DiffAnnotate") + function s:DiffAnnotate() + if !executable('filterdiff') + echohl WarningMsg + echo "You need to install filterdiff first (part of patchutils)" + echohl None + return + endif + let l:cursorpos = winsaveview() + %!filterdiff --annotate + call winrestview(cursorpos) + endfunction +endif + +" Print annotation of current hunk +if !exists("*s:DiffShowHunk") + function s:DiffShowHunk() + " if the current line begins with '+++' or '---', then it makes sense to search + " forwards + if getline(".") =~ '^+++ \|^--- ' + let l:lineno = search('^@@[ +-\,\d]*@@.*$', 'ncW') + else + let l:lineno = search('^@@[ +-\,\d]*@@.*$', 'bncW') + endif + if l:lineno == 0 + return + endif + let l:hunk_annotation = substitute(getline(lineno), '^@@[ +-\,\d]*@@\s*\(.*\)$', '\1', '') + echo l:hunk_annotation + endfunction +endif + +" Skip to next hunk +if !exists("*s:DiffNextHunk") + function s:DiffNextHunk() + call search('^@@[ +-\,\d]*@@', 'sW') + endfunction +endif + +" Skip to previous hunk +if !exists("*s:DiffPrevHunk") + function s:DiffPrevHunk() + call search('^@@[ +-\,\d]*@@', 'bsW') + endfunction +endif + +" Skip to next changed file +if !exists("*s:DiffNextFile") + function s:DiffNextFile() + call search('^--- ', 'sW') + endfunction +endif + +" Skip to previous changed file +if !exists("*s:DiffPrevFile") + function s:DiffPrevFile() + call search('^--- ', 'bsW') + endfunction +endif + +command! -buffer DiffAnnotate call s:DiffAnnotate() +command! -buffer DiffShowHunk call s:DiffShowHunk() +command! -buffer DiffNextHunk call s:DiffNextHunk() +command! -buffer DiffPrevHunk call s:DiffPrevHunk() +command! -buffer DiffNextFile call s:DiffNextFile() +command! -buffer DiffPrevFile call s:DiffPrevFile() + + +" Default },{,(,) do not make much sense in diffs, so remap them to +" make something useful +nnoremap } :DiffNextFile +nnoremap { :DiffPrevFile +nnoremap ) :DiffNextHunk +nnoremap ( :DiffPrevHunk + -- cgit