Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a VIM Git timeline?

So far, I am trying to understand how to use :Glog in combination with :Gdiff, to create a nice overview like the git-time-machine plugin for the Atom editor:

enter image description here

The overview exists of 3 windows

  1. On the left: the current file in the working copy.
  2. On the right: one of the previous versions of the file.
  3. On the bottom: a quickfix list filled with entries from the history.

When I select a commit from the quickfix list, the version will be placed in the right window. Not to forget the difference being highlighted.

Can someone help me? :)

like image 321
Sem Avatar asked Jul 19 '16 20:07

Sem


People also ask

Does Vim have git?

Modern Vim has a built-in terminal. That means you can always start :term and start using Git command-line interface like you're used to. You can also start a specific command like :term git status or :term git add % (where % refers to the current file path). For simple commands, even simple bang!

How do you use fugitive?

Adjective As he daydreamed, fugitive thoughts passed through his mind.


2 Answers

I'm not aware of a plugin that is exactly like that. But there's gitv, which is like gitk for vim.

screenshot of gitv

Even though it's currently not being actively maintained it's working quite well IMHO.

screenshot of gitv

screenshot of gitv Source

like image 71
mash Avatar answered Oct 09 '22 05:10

mash


Here are some commands that you can use to simulate a crude version of the behaviour you describe.

  • first, open the file that interests you
  • run :only to close any other split windows
  • run :Glog to populate the quickfix list with all past revisions of the file
  • note that you are now looking at the first item in the quickfix list, which should be the most recently committed version of the file
  • traverse forwards and back through the quickfix list using :cnext and :cprev

So far this is basic usage. Now suppose that you find yourself looking at a previous version of the file that you want to diff with the working copy. Here's how you could do that:

  • run :vsplit to divide your workspace into two split windows
  • then <C-w><C-h> to activate the left split
  • then run :Gedit, which loads the working copy version of the file you're looking at
  • then :windo diffthis

Boom! You've got a diff with the working copy on the left and the previous version on the right.

Now let's say that you want to keep the working copy in the left split, while traversing through other past versions in the right split:

  • use <C-w><C-l> to activate the right split
  • use :cprev/:cnext to go back/forwards through the quickfix list (the right split window will move out of diffmode, but the left split remains in diffmode)
  • run :diffthis to activate a diff between the current buffer and the working copy

When you're done looking at diffs, run:

  • :diffoff! to disable diff mode
  • and :only to collapse your workspace into a single split
  • optionally, use :Gedit to switch back to the working copy of the file you're working with

You could automate some of these steps using Vimscript, and you could also add the quickfix window at the bottom of the screen the way you suggested. It would make a neat plugin! Personally, I'm happy to run these commands by hand. This workflow looks complicated when written out, but it can become second nature with practice.

like image 44
nelstrom Avatar answered Oct 09 '22 04:10

nelstrom