Skip to content

Instantly share code, notes, and snippets.

@mageekguy
Last active January 5, 2017 21:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mageekguy/4713903 to your computer and use it in GitHub Desktop.
Save mageekguy/4713903 to your computer and use it in GitHub Desktop.
Add code below in your .vimrc to see the Git previous version of the current file with :GitPrevious.
function! s:GitPrevious()
let _ = './' . expand('%')
let filetype = &filetype
execute ':silent! vsp ' . tempname()
execute ':silent! 0r !git show HEAD~1:' . _
execute ':silent! $d'
execute ':silent! set nomodifiable'
execute ':silent! set readonly'
execute ':silent! set ft=' . filetype
setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile
endfunction
command! -nargs=0 GitPrevious call s:GitPrevious()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment