Open fugitive’s diff view for each modified file



git status has a --porcelain option which formats the output in a way that’s easy to parse in scripts. It can, for example, be combined with awk to list the path to each modified file like so:

git status --porcelain | awk '{print $2}'

A Vim buffer can be created for each of those modified files with the following:

vim $(git status --porcelain | awk '{print $2}')

If you don’t already use Tim Pope’s vim-fugitive plugin I’d highly recommend it. Amongst its many features is a diff view that shows a file’s working copy and index side by side. By once again building upon the above snippet we can open a diff for each of the modified files:

vim -p -c 'tabdo Gdiff' $(git status --porcelain | awk '{print $2}')

The -p flag tells Vim to open each file in a tab and -c 'tabdo Gdiff' tells it to run the Gdiff command in each of those tabs.

With my configuration, the resulting Vim session looks like this for a project with a fair few uncommitted changes:

Thanks for reading! If you liked this post, you may like others archived in: Git, Vim.