How to Refresh Git Diff Output in Vim

How to Refresh Git Diff Output in Vim

The command I use to check the project diff is

git diff | vimdiff -

Is there a way I can refresh the diff file without existing Vim and repeating the previous command?

3

2 Answers

The Vim instance only receives the diff information from stdin (via the | shell pipe), so there's no way to refresh that.

If you don't want to exit Vim and recall the command from the shell history, I would recommend using a plugin (like fugitive.vim - A Git wrapper so awesome, it should be illegal) that allows you to trigger (and re-trigger!) a diff from within Vim.

In Vim:

:%d | .!git diff

The first part deletes all lines, and the second runs git diff in the cwd and pipes the output of this command to the buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.