Now, I want to combine it with git to compare the current version and a previous version.
Now, I have tried to get that in a single command, without having to write a patch file.
You can easily create a custom command to do this:
command! -nargs=? PreviousVersion diffthis |
\ vnew |
\ set buftype=nofile |
\ set bufhidden=wipe |
\ set noswapfile |
\ execute "r!git show ".(!"<args>"?'head^':"<args>").":".expand('#') |
\ 1d_ |
\ let &filetype=getbufvar('#', '&filetype') |
\ execute 'autocmd BufWipeout <buffer> diffoff!' |
You can now do
:PreviousVersion to get the changes between the current buffer and the last commit (
head^) or some arbitrary revision, e.g.
Note: you may want to use
:new if you want more control over the splitting.
Alternatively, I would recommend using fugitive.vim's
I'm not going to lie to you; fugitive.vim may very well be the best Git wrapper of all time.
:Gvdiff to do the
Diff between the current file and the previous commit
Diff between current file and the index
Diff between current file and some other [revision]
Diff between current file and current file 3 commits ago:
:Gdiff is useful, I find
:Gblame to be more useful. I can "re-blame" at on a certain line or open a commit to see the patch. This article explains how useful
git blame can be: Every line of code is always documented.
Vimcasts has a Fugitive series which I highly recommend. I would suggest looking at episodes: Working with the git index and Resolving merge conflicts with vimdiff.
For more help see