I'm currently using vim 7.3 on Windows 7.

The first question I have is it even possible to create the patch file from within vim itself? I understand the basic idea, but anytime I attempt to run

diff -u file.txt file_new.txt > file.patch

I get a E488: Trailing characters error. However, using the Windows command prompt to run diff.exe from the vim folder seems to work just fine. I'm not sure if I'm doing something wrong here.

Second - and I'm sure there's an explanation in the manual but :help diff didn't seem to show anything - what's the difference between diff -u and diff -c? From what I saw online, both -u and -c were both used to create a patch file. When I tested it myself using the command prompt, they both appeared to generate identical files.

[Edit] I realized I must have done something wrong as I just checked again and the files generated by diff -u and diff -c are different. Still curious what the differences are and when I should use one or the other.

  • How did you run that command? :!diff -u file.txt file_new.txt > file.patch or diff -u file.txt file_new.txt > file.patch? It seems to me you're trying to run an external command directly in Vim.
    – muru
    Jun 22, 2015 at 15:31
  • That's exactly what I was trying to do because I'm an idiot.
    – Aetylus
    Jun 22, 2015 at 15:41

1 Answer 1


:!<cmd> is how we usually run external commands from within Vim. See :he :!. :diff presumably calls Vim's :diffget command, but definitely not the external diff program as you intended it.

:help diff won't say anything about difference between diff -u and diff -c, because those are options for the external diff program, and nothing to do with Vim. Assuming you're using GNU diff (POSIX diff doesn't specify -u), -u produces unified diffs, and -c produces a context diff with, 3 lines of context. See the GNU diff manual for more information.

It seems you must be using GNU diff, since the GNU docs say about unified diffs:

At present, only GNU diff can produce this format and only GNU patch can automatically apply diffs in this format.

  • 2
    At present, only GNU diff can produce this format and only GNU patch can automatically apply diffs in this format. - For suitable values of present. :) OpenBSD's diff and patch have supported unified patches since June 2003.
    – lcd047
    Jun 22, 2015 at 17:15
  • @lcd047 somebody needs to submit a patch for the GNU documentation.
    – muru
    Jun 22, 2015 at 19:53
  • Make sure it's a upatch!
    – AL the X
    Aug 22, 2016 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.