More I use “fugitive.vim” more I understand why the author belives:
fugitive.vim may very well be the best Git wrapper of all time.
At :Differnet, we care about quality software and filing a Pull Request is the only way an engineer can contribute to our projects. Part of my job at Different as a tech lead is to review the contributions from the other engineers in our team.
We’re using Github to host our projects and it comes with a decent interface for code reviews. However, the interface never becomes the ideal tool for me because:
- The syntax is highlighted using a colour scheme that my eyes are not familiar nor comfortable with it
- The interface itself gets slow easily
- The diff interface shows only the changes with a bit of context. You can extend the context but it’s a tedious task
Enter fugitive.vim. The one-stop-shop for all you need to review a change using Vim
In a nutshell, “fugitive.vim” is a vim plugin and a wrapper around Git. It brings Git to Vim. I’m not going to sell you “fugitive.vim” so please take a look at the fugitive.vim Github repo for the introduction and some screencasts.
But what I’m going to share with you is how I use the fugitive.vim’s :Gdiff command to compare changes in a file with the master version of the same file. To see the :Gdiff command in action, simply switch to a branch and open a file that has some changes in it and run :Gdiff master:%. Vim splits the screen into two, the left one shows the master version of your file and the right one shows the same file in current branch!
As I mentioned “fugitive.vim” is simply a wrapper around Git and it uses Vim’s diff feature to show the diff between two reversions of the same file. You can use the following shortcuts and options to customize your code review experience:
- By default, Vim folds unchanged lines. The zR command unfolds them all for you so you can see the whole file.
- za command does the opposite. It folds the unchanged lines for you.
- zo unfolds a section for you
- zc folds the unfolded section back
- If you need more context (The lines before and after a set of changes), use the :set diffopt=context=X to adjust the number of lines you wish to see
By using the Vim + fugitive.vim combo, I get to:
- customise the code review experience as I wish to
- browse the changes quickly as Vim is damn fast
- review the changes using the colour schema I use to write code
- have access to all Vim commands
- can quickly browse related filed without change of the context
That’s all for today. If you have any question or you got something related to share, feel free to post a comment below.