Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 4
    Is there a way to do this with vimdiff? I tried :w !vimdiff % - but without success.
    – Joe J
    Commented Aug 16, 2011 at 14:32
  • 27
    Can somebody explain that? I don't understand what's happening. I understand you're shelling out to diff. % refers to the currently open filepath. Why is all this an argument to the :w command? Also, how does - get assigned to the contents of the working buffer? Is that automatic in vim, that the contents of the buffer (or maybe a specific range in the buffer) gets assigned to stdin for shell commands? Commented Oct 7, 2013 at 15:39
  • 17
    @NathanWallace: It's an argument to :w because we're writing the file to the command (on stdin). In the command, - tells it to read from stdin.
    – chaos
    Commented Oct 7, 2013 at 16:15
  • 22
    Or use :w !git diff % - for a colorized version, if you have git installed!
    – Dergachev
    Commented Nov 26, 2015 at 17:29
  • 6
    @Dergachev I get the error fatal: bad flag '-' used after filename when I run :w !git diff % -.
    – Grayscale
    Commented Jul 26, 2018 at 3:08