Flaviu's Blog - Read'n'Code

View Old Git Version of a File in a Vim Split

Wouldn’t it be nice if you could view an old version of a file side by side with the current one in Vim? And it would scroll together? And syntax highlight?

Well, open the current file in a Vim window. Then do the following:

  1. Open a new (blank) split or window:
1
:vsp new
  1. Dump the old file contents in this new buffer: (note: ‘!’ executes a shell command, and ‘read’ puts it in the current buffer)
1
:read !git show HEAD^:path/to/file/from/root.py
  1. Set the right syntax highlighting:
1
:setf python
  1. Scroll bind the two splits: (note: you must run this command in both splits)
1
:set scrollbind

Hope this helps. Let me know if there’s a better way to do this.

Comments

Fork Flaviu on GitHub