4

How do I get a vimdiff view of the effects of patching a file?

Tom Hale
  • 2,681
  • 14
  • 32

1 Answers1

5

Use:

vim <file> +"vertical diffpatch <patch-file>"

Note the warning from :help inside this this script I call vimdiffpatch:

#!/bin/bash

if [[ $# -ne 2 ]]; then
  echo "Usage: $(basename "$0") <base-file> <patch-file>" 2>&1
echo
echo "From ':help diffpatch':"
echo "Note that {patchfile} should only contain a diff for one file,"
echo "the current file.  If {patchfile} contains diffs for other"
echo "files as well, the results are unpredictable.  Vim changes"
echo "directory to /tmp to avoid files in the current directory"
echo "accidentally being patched.  But it may still result in"
echo "various ".rej" files to be created.  And when absolute path"
echo "names are present these files may get patched anyway."

  exit 1
fi

vim "$1" +"vertical diffpatch $2"

For bonus points, highlight the exact differences, based on characters and words.

Tom Hale
  • 2,681
  • 14
  • 32