Let’s say I have a file f.txt under the git repository. The initial version of this file contains one line, version 2 contains 2 lines and every new version adds one line to the previous version, so the version 10 contains 10 lines.
Now, I open the file f.txt (in 5th version) in the vim editor. I’d like to stay in the vim editor and have the possibility of commands like git_next and git_previous and quickly switch between versions, without having to know commit numbers and without leaving vim.
Is there such a possibility of using git and vim? It would be also useful if I could type command like git_versions and I could choose from the list of versions of this file and switch to the desired version.
You are looking for Fugitive.vim plugin by Tim Pope. It can aid you with many
gitcommands.With fugitive.vim you can execute
:Glogand the revisions will be put into thequickfixlist. Just use:cnext,:cprev, and friends to move between the revisions. There is an excellent screencast, Fugitive.vim – exploring the history of a git repository, on this by Drew Neil. I would highly recommend watching all the Vimcasts on the subject.Drew in the screencast also shows off another Tim Pope plugin called Unimpaired.vim. I highly recommend it. It will provide some nice mappings (
[q,]q, etc.) to move through thequickfixlist.For more help see:
If you have Fugitive.vim installed see: