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 git
commands.
With fugitive.vim you can execute :Glog
and the revisions will be put into the quickfix
list. 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 the quickfix
list.
For more help see:
:h quickfix
:h :cnext
If you have Fugitive.vim installed see:
:h fugitive
:h fugitive-:Glog
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.